29 JavaScript之BOM基础

一、Bom基础:
打开、关闭窗口 window.open("url");
open
蓝色理想运行代码功能 补充document.write
document.write("abc");在页面上写下abc
放在时间里用:会先清空再写
平时使用document ,应该是window.document.xxx平时省略写
open(url,self/-blank/)返回来是新打开的窗口window对象
close、
简易的运行代码案例:
<!DOCTYPE HTML>
<html>
<head>
<title>运行代码效果</title>
<style>
#txt1{
width:200px;
height:200px;
background:#ccc;
}
</style>
<script>
window.οnlοad=function()
{
var oBtn =document.getElementById("btn1");
var oText=document.getElementById("txt1");
oBtn.οnclick=function()
{
//弹出空白页
var window1= window.open('about:blank','_blank');
window1.document.write(oText.value);
}
};
</script>
</head>
<body>
<textarea id="txt1"></textarea>
<input id="btn1" type="button" value="运行"></input>
<div>
</div>
</body>
</html>

打开关闭窗口的案例:
<input type="button" value="打开窗口"
οnclick="window.open('http.www.baidu.com')"
/>
<input type="button" value="关闭窗口" οnclick="window.close();"/>
但是使用window.close()时候有些问题:
在火狐下不允许脚本关闭由用户打开的窗口,只能关闭由程序员用open打开的窗口
常用属性
window.navigator.userAgent 指的是当前浏览器的版本信息 判断浏览器类型
window.location 当前网页的地址 还可以赋值 location的使用很多
二、尺寸和坐标
可视区顶部/左部距离网页顶部/左部距离
scrollTop=document.documentElement.scrollTop
scrollLeft=document.documentElement.scrollLeft
但是chrom兼容写法应该是document.body.scrollTop/document.body.scrollLeft
可视区的尺寸:
document.documentElement.clientHeight:可视区高度
document.documentElement.clientWidth 这就是可视区的宽度
固定定位案例:
#div1{
height:100px;
width:100px;
background:red;
position:fixed;
right:0px;
bottom:0px;
}这个固定定位在IE6中不兼容
解决方案:

红色浮动块的位置定位:由上图可知,垂直上的位置公式:
clientHeight-offsetHeight+scrollTop
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值