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
219 views
in Technique[技术] by (71.8m points)

javascript - Jquery to get the name of the current html file

If you are on http://www.cnn.com/2012/11/09/opinion/brown-pakistan-malala/index.html can you get Jquery to grab the index.html?

or if you are on http://www.washingtonpost.com/politics/decision2012/supreme-court-to-review-key-section-of-voting-rights-act/2012/11/09/dd249cd0-216d-11e2-8448-81b1ce7d6978_story.html have it return dd249cd0-216d-11e2-8448-81b1ce7d6978_story.html?

And for non extension defined pages such as this current one http://stackoverflow.com/questions/13317276/jquery-to-get-the-name-of-the-current-html-file can it return the last "file" in the "directory"structure, for example: jquery-to-get-the-name-of-the-current-html-file

See Question&Answers more detail:os

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

1 Reply

0 votes
by (71.8m points)

Although not JQuery, you can access it using the following:

document.location.href.match(/[^/]+$/)[0]

or

document.location.pathname.match(/[^/]+$/)[0] in case of unneeded anchors/hash tags (#).


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

...