当前位置: 首页 > 图文教程 > 网络编程 > Javascript > JS 中document.URL 和 windows.location.href 的区别

Javascript
form中限制文本字节数js代码
use jscript with List Proxy Server Information
use jscript List Installed Software
List Installed Software Features
List Information About the Binary Files Used by an Application
List the Codec Files on a Computer
List the UTC Time on a Computer
List Installed Hot Fixes
excel操作之Add Data to a Spreadsheet Cell
Add Formatted Data to a Spreadsheet
Apply an AutoFormat to an Excel Spreadsheet
JavaScript语法着色引擎(demo及打包文件下载)
类之Prototype.js学习
一款JavaScript压缩工具:X2JSCompactor
iis6+javascript Add an Extension File
jscript之Open an Excel Spreadsheet
jscript之Read an Excel Spreadsheet
jscript之List Excel Color Values
去除图像或链接黑眼圈的两种方法总结
Add a Formatted Table to a Word Document

Javascript 中的 JS 中document.URL 和 windows.location.href 的区别


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2010-01-10   浏览: 544 ::
收藏到网摘: n/a

实际上,document 和 windows 这两个对象的区别已经包含了这个问题的答案。 document 表示的是一个文档对象,windows 表示一个窗口对象。
一个窗口下面可以有很多的document对象。每个document 都有 一个URL。
但是,这不是所有的区别。当你ctrl + F5 一个链接 http://www.ruanchen.com/server
打印 alert(document.URL ); 和 alert(windows.location.href);
发现,这两个的值不一样,
document.URL : http://www.ruanchen.com/
windows.location.href :http://www.ruanchen.com/server
所以,如果要用 fragment 进行相应的处理的话,最好是用 windows.location.href
否则会出现很奇怪的错误。