Jquery to get the name of the current html file

后端 未结 4 1974
温柔的废话
温柔的废话 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 17:15

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

提交回复
热议问题