js- BOM

BOM:Browser Object Model 浏览器对象模型

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

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

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

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

<!DOCTYPE html>
<html>
    <head>
        <meta charset="{CHARSET}">
        <title></title>
        <script>
            window.onload = function(){
                var aInput = document.getElementsByTagName('input');
                aInput[0].onclick = function(){
                    window.open();
                }

            }
        </script>
    </head>
    <body>
        <input type="button" value="打开新窗口" />
    </body>
</html>

aInput[0].onclick = function(){
          window.open('http://www.baidu.com','_self');
 }

打开的新窗口,可以对新窗口进行操作

<!DOCTYPE html>
<html>
    <head>
        <meta charset="{CHARSET}">
        <title></title>
        <script>
            window.onload = function(){
                var aInput = document.getElementsByTagName('input');
                aInput[0].onclick = function(){
                    opener = window.open();
                    opener.document.body.style.background = 'red';
                }

            }
        </script>
    </head>
    <body>
        <input type="button" value="打开新窗口" />
    </body>
</html>

close()方法 关闭窗口

aInput[1].onclick = function(){
                    window.close();
                }
            }
        </script>
    </head>
    <body>
        <input type="button" value="打开新窗口" />
        <input type="button" value="关闭新窗口" />
    </body>

注意:1、火狐:默认无法关闭

           2、chrome:直接关闭

           3、ie:询问用户

可以关闭在本窗口中通过js方法打开的新窗口

<!DOCTYPE html>
<html>
    <head>
        <meta charset="{CHARSET}">
        <title></title>
        <script>
            window.onload = function(){
                var aInput = document.getElementsByTagName('input');
                aInput[0].onclick = function(){
                    opener = window.open();
                    opener.document.body.style.background = 'red';
                }
                aInput[1].onclick = function(){
                    window.close();
                }
                aInput[2].onclick = function(){
                    opener.close();
                }

            }
        </script>
    </head>
    <body>
        <input type="button" value="打开新窗口" />
        <input type="button" value="关闭窗口" />
        <input type="button" value="关闭新窗口" />
    </body>
</html>

window.navigator.userAgent->浏览器信息

<!DOCTYPE html>
<html>
    <head>
        <meta charset="{CHARSET}">
        <title></title>
        <script>
            alert(window.navigator.userAgent);
        </script>
    </head>
    <body>
    </body>
</html>

window.location:浏览器地址信息   是一个对象

window.location.href   ===  window.location  (地址栏地址信息)

<!DOCTYPE html>
<html>
    <head>
        <meta charset="{CHARSET}">
        <title></title>
        <script>
            alert(window.location);
        </script>
    </head>
    <body>
    </body>
</html>

window.location.search:url?后面的内容

window.location.hash:url#后面的内容

 

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值