Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
210 views
in Technique[技术] by (71.8m points)

javascript - 使用JavaScript获取当前URL?(Get the current URL with JavaScript?)

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

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

1 Reply

0 votes
by (71.8m points)

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,只读 。)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...