简体   繁体   English

如何找到当前页面的网址(例如“ index.html”)?

[英]How to find current page url (like “index.html”)?

With string http://www.example.com/section_one/index.html how can I return index using RegExp? 使用字符串http://www.example.com/section_one/index.html如何使用RegExp返回index
PS: Returning index.html is accepted too. PS:也返回index.html

You don't need to use regex for that. 您不需要为此使用正则表达式。 Its simple: 这很简单:

var url = document.URL;
var currentPage= url.split("/").pop();

You can try the following. 您可以尝试以下方法。 Fiddle 小提琴

var url = "http://www.example.com/section_one/index.html";
var filename = url.match(/[^\\/]+$/)[0];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 ReactJS - 刷新页面总是将 URL 更改为 index.html - ReactJS - Refreshing the page always changes URL to index.html 如何在index.html页面中基于url使用ng-if? - how can I use ng-if based on url in the index.html page? 在网址中隐藏index.html - hide index.html in the URL 如何从网站上的url中删除index.html基于angularjs - How to remove index.html from url on website based on angularjs 如何在 swagger-UI 中的 index.html 中设置 url - How to set url in index.html in swagger-UI 带有地理位置警报的Ionic:'mySecondApp.app/www/index.html'想使用您的当前位置 - Ionic with Geolocation alerts: 'mySecondApp.app/www/index.html' Would like to use your current location 浏览器如何在单个页面应用程序上缓存index.html - How works browser caching for index.html on a single page application 如果页面是index.html,如何运行jquery脚本 - How to run jquery script if page is index.html 如何使用Python / Flask在heroku中显示index.html页面 - How to show index.html page in heroku using Python/Flask 如何使AngularJS路由与index.html /#/ myPage一样工作,如index.html#/ myPage - How to make AngularJS route works with index.html/#/myPage like index.html#/myPage
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM