zoukankan      html  css  js  c++  java
  • window.open与window.close的兼容性问题

    window.open(页面地址url,打开的方式) 方法 打开一个新的窗口(页面)

                       如果url为空,则默认打开一个空白页面

                       如果打开方式为空,默认为新窗口方式打开

    返回值:返回新打开窗口的window对象

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Document</title>
    </head>
    <body>
        <button type="button" id="btn">打开新窗口</button>
    
        <script type="text/javascript">
        var btn = document.getElementById('btn');
        btn.onclick = function(){
            var opener = window.open('http://www.baidu.com','_self');
            opener.document.body.style.background = 'red'; //不能跨域,只能修改同域名下的。
        }
        </script>
    </body>
    </html>

    window.close()方法 关闭窗口

    关闭默认的窗口是有兼容性问题的:

    1、ff:默认无法关闭

    2、chrome:默认直接关闭

    3、ie:询问用户

    关闭在本窗口中通过js方法打开的新窗口是没有兼容性问题的

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Document</title>
    </head>
    <body>
        <button type="button">打开新窗口</button>
        <button type="button">关闭新窗口</button>
    
        <script type="text/javascript">
        var btn = document.getElementsByTagName('button'),
            opener = null;
    
        btn[0].onclick = function(){
            opener = window.open('http://www.baidu.com','_blank');
            opener.document.body.style.background = 'red'; //不能跨域,只能修改同域名下的。
        }
        btn[1].onclick = function(){
            opener.close();
        }
        </script>
    </body>
    </html>
  • 相关阅读:
    史上最简洁的handler原理解释
    handler解惑
    Http中get和post的区别
    使用软引用缓存Bitmap
    Request头和Response头
    DNS编程实验--域名与IP的相互转换
    CString与string
    C++ string占多少个字节测试
    java中类的继承性和多态性实例
    java寻找html文件中的标签
  • 原文地址:https://www.cnblogs.com/gongshunkai/p/5842688.html
Copyright © 2011-2022 走看看