zoukankan      html  css  js  c++  java
  • 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>
  • 相关阅读:
    更改Tomcat startup.bat启动窗口名称
    java 启用新线程异步调用
    [转]jquery中使用event.target的几点
    Linux开启相关端口及查看已开启端口
    【转】eclipse插件:OpenExplorer快速打开文件目录
    bootbox.js [v4.2.0]设置确认框 按钮语言为中文
    【转】eclipse使用git提交到osc
    使用RMAN恢复数据库
    来一篇最全的自动化运维部署文档
    (转)linux 内存管理——内核的shmall 和shmmax 参数
  • 原文地址:https://www.cnblogs.com/bigben0123/p/13954281.html
Copyright © 2011-2022 走看看