• iframe


    父层下操作iframe

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Document</title>
        <script>
        window.onload = function(){
            //chrome中要在服务器下访问才行
            var oBtn = document.getElementById("btn1");
            var oIframe = document.getElementById("iframe1");
            
            oBtn.onclick = function(){
                //oIframe.contentWindow  >>  iframe window object
                //oIframe.contentDocument  >>  iframe document object
    
                //oIframe.contentWindow.document.getElementById("div1").style.backgroundColor = "red";
                oIframe.contentDocument.getElementById("div1").style.backgroundColor = "red";//ie6,7不支持
            };
        };
        </script>
    </head>
    <body>
        <input type="button" id="btn1" value="改变">
        <iframe src="iframe.html" id="iframe1"></iframe>
    </body>
    </html>
    View Code

    iframe中操作父层

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Document</title>
        <script>
        window.onload = function(){
            var oBtn = document.getElementById("btn1");
            
            oBtn.onclick = function(){
                //window.parent.document.getElementById("div1").style.backgroundColor = "red";//父层
    
                window.top.document.getElementById("div1").style.backgroundColor = "red";//最顶层
            };
        };
        </script>
    </head>
    <body>
        <input type="button" id="btn1" value="改变">
    </body>
    </html>
    View Code

    iframe onload事件

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Document</title>
        <script>
            
        window.onload = function(){
            var oBtn = document.getElementById("btn1");
    
            oBtn.onclick = function(){
                var oIframe = document.createElement("iframe");
                oIframe.src = "iframe.html";
                document.body.appendChild(oIframe);
                // oIframe.onload = function(){
                //     alert(1);
                // };
                //ie下iframe的onload只能在绑定下使用
    
                if(oIframe.attachEvent){
                    oIframe.attachEvent('onload',function(){
                        alert(123);
                    });
                }
                else{
                    oIframe.addEventListener('load',function(){
                        alert(123);
                    });
                }
            };
        };
        </script>
    </head>
    <body>
        <input type="button" value="加载" id="btn1">
    </body>
    </html>
    View Code

    防钓鱼

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Document</title>
        <script>
        if(window != window.top){
            window.top.location.href = window.location.href;     
        }
        </script>
    </head>
    <body>
        <div id="div1">aaa</div>
    </body>
    </html>
    View Code

    setTimeout 延迟执行 操作iframe

  • 相关阅读:
    小小小康
    GC日志补充
    一次GC问题定位
    mycat1.5~1.6的一个bug
    [转] java Statement和PreparedStatement批量更新
    java 中的instanceof 运算符
    Java学习篇之数组方法
    iOS7适配的一点小技巧
    iOS 中正确切换摄像头&正确实现设置帧率的方式
    iOS 音量键事件监控响应
  • 原文地址:https://www.cnblogs.com/jiujiaoyangkang/p/5877988.html
Copyright © 2020-2023  润新知