js function to get filename from url

前端 未结 19 2573
挽巷
挽巷 2020-11-30 03:01

I have a url like http://www.example.com/blah/th.html

I need a javascript function to give me the \'th\' value from that.

All my urls have the same format (2

19条回答
  •  挽巷
    挽巷 (楼主)
    2020-11-30 03:32

    Similar to the others, but...I've used Tom's simple script - a single line,
    then you can use the filename var anywhere:
    http://www.tomhoppe.com/index.php/2008/02/grab-filename-from-window-location/

    var filename = location.pathname.substr(location.pathname.lastIndexOf("/")+1);
    

提交回复
热议问题