Javascript echo [removed]

2019-07-20 00:05发布

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

now I want to assign this location path to a variable, as a normal text string. I want to achieve:

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

i tried to use:

var Path = window.location;

but I get, as this var value:

function Path() { [native code] }

while I want to have the location text string as its value..

4条回答
爱情/是我丢掉的垃圾
2楼-- · 2019-07-20 00:27

You want location.href. The location object is rather more complicated than a simple string.

查看更多
Root(大扎)
3楼-- · 2019-07-20 00:27

You can try

var Path = window.location.toString();
查看更多
家丑人穷心不美
4楼-- · 2019-07-20 00:41

This should work (though I didn't test):

var path = window.location.href;
查看更多
爷的心禁止访问
5楼-- · 2019-07-20 00:42

Yes, window.location is an object, its href property returns the entire URL.

See here for a reference on the location object (location's other properties & functions can be useful): http://developer.mozilla.org/en/DOM/window.location

查看更多
登录 后发表回答