document.location和window.location有什么区别?

浴火_凤凰 2010-01-05 10:19:09
document.location和window.location有什么区别啊?
我大部分情况下是使用window.location
但是发现别人有使用document.location的,不知道二者有什么区别?
还有就是document.locationdocument.location.href和document.location.href有什么区别?
window.location和window.location.href有什么区别?

有的书上还提到了document.URL这个属性,document.URL
又是做什么的?貌似是跟document.location作用一样,
请高手指点一下!谢谢!!!
...全文
20229 25 打赏 收藏 转发到动态 举报
写回复
用AI写文章
25 条回复
切换为时间正序
请发表友善的回复…
发表回复
xinjirufen1 2012-01-19
  • 打赏
  • 举报
回复
脑袋瓜子真好用。[Quote=引用 5 楼 xiaojing7 的回复:]

[/Quote]
翱翔的小鸟66 2012-01-14
  • 打赏
  • 举报
回复
明白明白
乘桴游海 2011-11-04
  • 打赏
  • 举报
回复
$(window).width()
$(document).width()啥区别啊?
qumenglin218 2010-05-20
  • 打赏
  • 举报
回复
顶14楼,
lord_is_layuping 2010-04-26
  • 打赏
  • 举报
回复
document.location is deprecated in favor of window.location, which can be accessed by just location, since it's a global object.

The location object has multiple properties and methods. If you try to use it as a string then it acts like location.href. To be on the safe side it's best to always use location.href when that's what you mean.
meilixinqinggmq 2010-02-05
  • 打赏
  • 举报
回复
我没有用框架,但是用window.location不跳转,用document.location可以
happy002 2010-01-07
  • 打赏
  • 举报
回复
mark
lodachi 2010-01-07
  • 打赏
  • 举报
回复
[Quote=引用 17 楼 lodachi 的回复:]
JavaScript原文摘录:
[/Quote]是JavaScript权威指南 原文摘录
lodachi 2010-01-07
  • 打赏
  • 举报
回复
JavaScript原文摘录:
不要混淆Window对象的location属性和Document对象的location属性。前者引用一个Location对象,而后者只是一个只读字符串,并不具有Location对象的任何特性。document.location与document.URL是同义的,后者在JavaScript1.1中是该属性的首选名称(因为这样避免了潜在的混淆)。在大多数情况下,document.location和location.href是相同的。但是,当存在服务器重定向时,document.location包含的是已经装载的URL,而location.href包含的则是原始请求的文档的URL。
eduyu 2010-01-07
  • 打赏
  • 举报
回复
没有区别,document.location是老标准。新标准规定location对象是全局对象,也就是挂在window对象下。
maoshulin 2010-01-06
  • 打赏
  • 举报
回复
document.location和window.location有什么区别就是
document你可以理解为文档,就是你的网页
window理解为窗口,就是你的ie浏览器包含的

无框架:简单的说,没有框架的情况下,是等同的
有框架:在有框架的情况下,最外层是相同的,在iframe里面的document.location和window.location不同的。
iframe里面的document.location 你看不ie地址变化,只改变iframe部分,
此时的window.location和top.location效果一致
j2eeoriented 2010-01-06
  • 打赏
  • 举报
回复
m
zhyzdl 2010-01-05
  • 打赏
  • 举报
回复
study
hehuan1213 2010-01-05
  • 打赏
  • 举报
回复
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';//改变框架内容
nobody@noone 2010-01-05
  • 打赏
  • 举报
回复
你这个问题实际上就是问window对象和document对象的区别嘛
一般来讲,一个window里就是一个document,但是,iframe里面也可以装个document,在iframe里面就有区别了
antony1029 2010-01-05
  • 打赏
  • 举报
回复
jf
asharpnet 2010-01-05
  • 打赏
  • 举报
回复
也是不明白其中的区别
yixianggao 2010-01-05
  • 打赏
  • 举报
回复
试验一下

L@_@K
alert(document.location === window.location); // true
xiaojing7 2010-01-05
  • 打赏
  • 举报
回复
xiaojing7 2010-01-05
  • 打赏
  • 举报
回复
加载更多回复(4)

87,994

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧