window.location = 'http://...';现在我想将这个位置路径分配给一个变量,作为一个普通的文本字符串。我希望实现以下目标:
var Path = 'http://...';我试着使用:
var Path = window.location;但是我得到了这个var值:
function Path() { [native code] }虽然我希望将位置文本字符串作为它的值..
发布于 2011-05-29 01:31:40
是的,window.location是一个对象,它的href属性返回整个URL。
有关location对象(location的其他属性和函数可能很有用)的参考信息,请参阅此处:http://developer.mozilla.org/en/DOM/window.location
发布于 2011-05-29 01:19:38
你想要location.href。location对象比简单的字符串复杂得多。
发布于 2011-05-29 01:20:32
这应该可以工作(虽然我没有测试):
var path = window.location.href;https://stackoverflow.com/questions/6163163
复制相似问题