Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 444
chris Frisina Avatar asked Nov 09 '12 22:11

chris Frisina


People also ask

How to find current URL in jQuery?

The current URL in jQuery can be obtained by using the 'href' property of the Location object which contains information about the current URL. The 'href' property returns a string with the full URL of the current page.

What is $$ jQuery?

jQuery is an object provided by jQuery. $ is another, which is just an alias to jQuery . $$ is not provided by jQuery. It's provided by other libraries, such as Mootools or Prototype. js.


Video Answer


1 Answers

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 (#).

like image 153
Vyacheslav Voronchuk Avatar answered Oct 03 '22 20:10

Vyacheslav Voronchuk