• js designMode 属性变化 自定义通知


    js代码:

    <!DOCTYPE html>
    <html lang="en">
    
    <head>
        <meta charset="UTF-8">
        <title>Title</title>
    </head>
    
    <body>
        <button onclick="modify()"> modify designMode</button>
        <button onclick="register()"> manual register event</button>
        <iframe id="nihao">
        </iframe>
        <script>
           var iframe = document.querySelector("#nihao");
    
            //这里注册没有用。因为后面执行了 document.close()
            window.addEventListener('cust_event_notify_attr_changed', function (event) {
                console.log("=== cust_event_notify_attr_changed from top window ===");
            }, false);
            iframe.contentWindow.addEventListener('click', function (event) {
                console.log("=== onclick iframe click from top window===");
            }, false);
    
            iframe.contentWindow.document.open();
            iframe.contentWindow.document.write("<!DOCTYPE html> <html><body><h3>nihao</h3></body></html>");
            iframe.contentWindow.document.close();
    
            //这里注册才有用。
            console.log("== register cust_event_notify_attr_changed ==");
            iframe.contentWindow.addEventListener('cust_event_notify_attr_changed', function (event) {
                console.log("=== cust_event_notify_attr_changed  from iframe===");
            }, false);
            iframe.contentWindow.addEventListener('click', function (event) {
                console.log("=== onclick iframe click from iframe===");
            }, false);
    
            iframe.contentWindow.document.designMode = "on";
    
            function modify() {
                document.querySelector("#nihao").contentWindow.document.designMode = "off";
            }
    
            function register() {
                var iframe = document.querySelector("#nihao");
    
                iframe.contentWindow.addEventListener('cust_event_notify_attr_changed', function (event) {
                    console.log("=== cust_event_notify_attr_changed from iframe again===");
                }, false);
    
                iframe.contentWindow.addEventListener('click', function (event) {
                    console.log("=== onclick iframe click===");
                }, false);
            }
        </script>
    </body>
    </html>
  • 相关阅读:
    [转]Ubuntu设置Redhat风格的SHELL提示符PS1属性
    [转]Ubuntu Adsl 上网
    [转]Bash中的PS1详解
    Verilog 关于用task仿真应注意的一个问题
    [转]提高编程技能最有效的方法
    [转]ubuntu 终端常用命令
    [转]VMware Workstation 7.1 正式版 For Linux
    [转]Vim基本操作
    [转]Ubuntu Linux下设置IP的配置命令
    xilinxftp.newlocation
  • 原文地址:https://www.cnblogs.com/bigben0123/p/13954281.html
Copyright © 2020-2023  润新知