Jquery to get the name of the current html file

后端 未结 4 1971
温柔的废话
温柔的废话 2020-12-15 16:16

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 a

4条回答
  •  眼角桃花
    2020-12-15 16:50

    No need for jQuery. This will give you the last segment of the URL path (the bit after the last slash):

    var href = document.location.href;
    var lastPathSegment = href.substr(href.lastIndexOf('/') + 1);
    

提交回复
热议问题