JS问题(window对象)

来源:百度知道 编辑:UC知道 时间:2024/06/25 15:23:24
location.href属性包含的URL与document.URL属性相同,但document.URL的属性只能返回不能修改,儿location.href的属性是可以更改的,因此可以使用loction.href来打开新页面。
这句话怎么理解呢?

下面是我的理解,location是地址对象,因此location.href指的就是域名
例如:http://www.baidu.com
而document是文档对象,因此document.URL指的就是文档的路径
例如:ABCD.html存在与桌面上,document.URL就是C:\Documents and Settings\Administrator\桌面
而书上说,location.href属性包含的URL与document.URL属性相同,这句话怎么理解啊 按照我的理解 好像不是那样子的啊 还有就是 document.URL的属性只能返回不能修改,而location.href的属性是可以修改的,因此可以使用location.href来打开新页面 这又是怎么回事啊?

+++++++++++++++ 一定要弄个例子啊 +++++++++++++++++JS例子:
<html>
<head>
<title>
</title>
<script language="java/language">

//解释代码
</script>
</head>
</html>

麻烦高人给我这个菜鸟指点指点,回答让我明白了,我高分悬赏!!谢谢了

引用w3c规范的说明:
document.URL:
URL of type DOMString, readonly The absolute URI [IETF RFC 2396] of the document.
http://www.w3.org/TR/2003/REC-DOM-Level-2-HTML-20030109/DOM2-HTML.html#html-ID-46183437

location.href:
The value of the href attribute MUST be the absolute URI reference [RFC2396]
use newer URI RFC?
that is the Location's current location. When the href attribute is set, the Location's window MUST navigate to the newly set value.
Must define the term navigate
http://www.w3.org/TR/Window/
从文档描述来看document.url和location.href确实是同样的功能。都是显示当前绝对路径。
但是document在标准中定义是只读的,因为IE不是遵循w3c标准的浏览器,所以没有严格遵守规则. 你可以用firefox试验一下,document.URL="xxx",肯定报readonly错误的.

给我