Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

All I want is to get the website URL.

(我想要的只是获取网站URL。)

Not the URL as taken from a link.

(不是从链接获取的URL。)

On the page loading I need to be able to grab the full, current URL of the website and set it as a variable to do with as I please.

(在页面加载中,我需要能够获取网站的完整,当前的URL,并将其设置为一个变量,以便我随意使用。)

  ask by translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
182 views
Welcome To Ask or Share your Answers For Others

1 Answer

Use:

(采用:)

window.location.href 

As noted in the comments, the line below works, but it is bugged for Firefox.

(如评论中所述,下面的行有效,但对于Firefox而言是错误的。)

document.URL;

See URL of type DOMString, readonly .

(请参阅DOMString类型的URL,只读 。)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...