Request address in JavaScript

Possible Duplicate:
Get current URL with JavaScript?

How do you get the address of the page you are on in JavaScript?

For example, if I had a script at somesite.com/javascript/home.html and I want to find out the request address ( somesite.com/javascript/home.html ), how do I get this information in JavaScript?


You need to use: document.location or window.location

You can read more here. Or there is a little more explanation over there.

For clarifying matter:

Originally Posted by Mozilla Developer Center

document.location was originally a read-only property, although Gecko browsers allow you to assign to it as well. For cross-browser safety, use window.location instead.


window.location.href;

or

location.href; 

window is the global object, so location.href will be identical to window.location.href and NOT document.location.href (as long as there's no enclosing function or with statement which shadows the property)


你在找什么是window.location.href 。

链接地址: http://www.djcxy.com/p/3850.html

上一篇: 在JavaScript中window.location和document.location有什么区别?

下一篇: 请求地址在JavaScript中