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
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.
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.
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 (#).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With