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>
  • 相关阅读:
    Pytorch:常用工具模块
    Pytorch: torch.nn
    流行框架阶段·概览
    jquery/js实现一个网页同时调用多个倒计时(最新的)
    用js判断页面刷新或关闭的方法
    js中substr,substring,indexOf,lastIndexOf,split 的用法
    jsonp案例
    CSS布局奇技淫巧:各种居中
    IntelliJ Idea 常用快捷键列表
    jquery中attr和prop的区别
  • 原文地址:https://www.cnblogs.com/bigben0123/p/13954281.html
Copyright © 2011-2022 走看看