3
window.location = 'http://...';

现在我想将此位置路径分配给一个变量,作为一个普通的文本字符串。我想实现:

var Path = 'http://...';

我尝试使用:

var Path = window.location;

但我得到了,因为这个 var 值:

function Path() { [native code] }

虽然我想将位置文本字符串作为其值..

4

4 回答 4

6

你想要location.href。该location对象比简单的字符串要复杂得多。

于 2011-05-28T17:19:37.640 回答
4

这应该有效(尽管我没有测试):

var path = window.location.href;
于 2011-05-28T17:20:31.683 回答
3

是的,window.location是一个对象,它的href属性返回整个URL。

有关location对象的参考,请参见此处(location的其他属性和功能可能很有用):http: //developer.mozilla.org/en/DOM/window.location

于 2011-05-28T17:31:40.103 回答
0

你可以试试

var Path = window.location.toString();
于 2015-01-05T18:21:11.127 回答