window.location = 'http://...';
现在我想将此位置路径分配给一个变量,作为一个普通的文本字符串。我想实现:
var Path = 'http://...';
我尝试使用:
var Path = window.location;
但我得到了,因为这个 var 值:
function Path() { [native code] }
虽然我想将位置文本字符串作为其值..
window.location = 'http://...';
现在我想将此位置路径分配给一个变量,作为一个普通的文本字符串。我想实现:
var Path = 'http://...';
我尝试使用:
var Path = window.location;
但我得到了,因为这个 var 值:
function Path() { [native code] }
虽然我想将位置文本字符串作为其值..
你想要location.href
。该location
对象比简单的字符串要复杂得多。
这应该有效(尽管我没有测试):
var path = window.location.href;
是的,window.location
是一个对象,它的href
属性返回整个URL。
有关location
对象的参考,请参见此处(location
的其他属性和功能可能很有用):http: //developer.mozilla.org/en/DOM/window.location
你可以试试
var Path = window.location.toString();