BOM应用(open、close、scrollTop)

 打开、关闭窗口:

  • open
<body>
<input type="button" value="打开窗口" onclick="window.open('http://www.baidu.com')"/>
</body>

document.write:先清空然后再写。

<body>
<input type="button" value="write" onclick="document.write('abc')"/><!--一点击按钮 按钮消失 abc出现-->
</body>

点击按钮,运行代码:

 <script>
        window.onload=function(){
            var oTxt=document.getElementById('txt1');
            var oBtn=document.getElementById('btn1');

            oBtn.onclick=function(){
                var oNewWin=window.open('about:blank','_blank');
                oNewWin.document.write(oTxt.value);
               // document.write()--window.document.write()
            }
        }
    </script>
</head>
<body>
<textarea id="txt1" cols="30" rows="10"></textarea> <br/>
<input type="button" value="运行" id="btn1"/>
</body>
  • close

     火狐中,close只能关闭open打开的窗口。

 <script>
        alert(window.navigator.userAgent);//当前浏览器版本信息
        alert(window.location)//当前页面的地址
 </script>

如果open给self的话就是location.

<body>
<input type="button" value="aaa" onclick="window.location='http://www.zhinengshe.com/';"/>
</body>

尺寸及坐标:

<script>
        document.onclick=function(){
//IE、火狐兼容
            alert(document.documentElement.scrollTop);
//chrome
            alert(document.body.scrollTop);
        }
</script>

<body style="height: 2000px;">
</body>

 scrollTop的兼容:

<script>
        document.onclick=function(){
            var scrollTop=document.documentElement.scrollTop||document.body.scrollTop;
            alert(scrollTop);
        }
</script>

右下角悬浮框:IE6不认fixed。

 <style>
        #div1{
            width: 100px;
            height: 200px;
            background: red;
            position: absolute;
            right: 0;
            bottom: 0;
        }
        body{
            height: 2000px;
        }

    </style>
    <script>
        //经常重新定位,所以会抖。
        window.onscroll=function(){
            var oDiv=document.getElementById('div1');
            var scrollTop=document.documentElement.scrollTop||document.body.scrollTop;
            oDiv.style.top=document.documentElement.clientHeight-oDiv.offsetHeight+scrollTop+'px';

        }
    </script>
</head>
<body>
<div id="div1"></div>

</body>

但是当改变可视区的大小时,悬浮框一开始不会随着变化,那是因为没有重新定位。

 <script>
        //经常重新定位,所以会抖。
        window.onscroll=window.onresize=function(){//window.onresize可视区大小移动时,重新定位
            var oDiv=document.getElementById('div1');
            var scrollTop=document.documentElement.scrollTop||document.body.scrollTop;
            oDiv.style.top=document.documentElement.clientHeight-oDiv.offsetHeight+scrollTop+'px';

        }
    </script>

解决抖动的问题:

userAgent>IE6        fixed

IE6                          运动

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值