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>
  • 相关阅读:
    中文字体
    URL锚点HTML定位技术机制
    关于JS异步加载方案
    select标签用法
    javascript refresh page 几种页面刷新的方法
    用JavaScript刷新框架子页面的七种方法
    robots.txt用法
    netstat 基本用法
    linux下ps命令
    socket编程和并发服务器
  • 原文地址:https://www.cnblogs.com/bigben0123/p/13954281.html
Copyright © 2011-2022 走看看