最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

string - Javascript echo window.location - Stack Overflow

programmeradmin0浏览0评论
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..

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..

Share Improve this question asked May 28, 2011 at 17:16 serytankianserytankian 2051 gold badge4 silver badges9 bronze badges
Add a comment  | 

4 Answers 4

Reset to default 7

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

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

var path = window.location.href;

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

You can try

var Path = window.location.toString();
发布评论

评论列表(0)

  1. 暂无评论