Js中window与document对象的区别

 

 

window对象和document对象的区别:
一般来讲,一个window里就是一个document,但是,iframe里面也可以装个document,在iframe里面就有区别了alert(document.location === window.location); // true

不要混淆Window对象的location属性和Document对象的location属性。前者引用一个Location对象,而后者只是一个只
读字符串,并不具有Location对象的任何特性。document.location与document.URL是同义的,后者在
JavaScript1.1中是该属性的首选名称(因为这样避免了潜在的混淆)。在大多数情况下,document.location和
location.href是相同的。但是,当存在服务器重定向时,document.location包含的是已经装载的URL,而
location.href包含的则是原始请求的文档的URL。

document.location和window.location有什么区别就是:
document你可以理解为文档,就是你的网页
window理解为窗口,就是你的ie浏览器包含的
无框架:简单的说,没有框架的情况下,是等同的
有框架:在有框架的情况下,最外层是相同的,在iframe里面的document.location和window.location不同的。
iframe里面的document.location 你看不ie地址变化,只改变iframe部分,
此时的window.location和top.location效果一致

document.location="url";(只读)
document.location.reload("url";);
window.location="url";
location="url";
document.href="url"
document.location.href="url"
document.location.replace="url"
document.action="url"; document.submit();
document.location.href和document.location.replace都可以实现从A页面切换到B页面,但他们的区别是:
用document.location.href切换后,可以退回到原页面。而用document.location.replace切换后,不可以通过“后退”退回到原页面。
关于document.location.href或其他可回退的切换方式
document.location 相当于 document.URL 声明了装载文档的URL,
除非发生了服务器重定向, 否则该属性的值与Window.location.href的值是一样的.
history.go(-1);//返回上一页
document.IFRAME名称.location.href='url';//改变框架内容 
       

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值