iframe页面之间的操作

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u010271602/article/details/77648738

子页面:

<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>子页面demo</title>
    <script type="text/javascript">
    window.onload = function(){
        var _iframe = window.parent;
        var _div =_iframe.document.getElementById('parDiv');
        _div.style.color = 'red';
    }
    </script>
</head>
 
<body>
    <div id='objId' style='width:100px;height:100px;background-color:red;'>子页面</div>
</body>
</html>
父页面:

<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>demo主页面</title>
    <script type="text/javascript">
    window.onload = function(){
        var _iframe = document.getElementById('iframeId').contentWindow;
        var _div =_iframe.document.getElementById('objId');
        _div.style.backgroundColor = '#ccc';
    }
    </script>
</head>
 
<body>
 
<div id='parDiv'>父页面</div>
<iframe src="c.html" id="iframeId" height="150" width="150"></iframe>
</body>
</html>






猜你喜欢

转载自blog.csdn.net/u010271602/article/details/77648738