本文介绍了从地址栏获取页面文件名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想知道是否可以使用jquery或javascript从地址栏获取页面名称。我知道这可以使用PHP来完成,但并不是真的想要,因为它只是一个HTML网站。
如果地址是 www.mywebsite.com/hello.htm
如何获取 hello.htm
部分地址。
感谢您提供任何帮助。
>
alert(location.pathname)
如果您不想使用前导斜杠,可以将其去掉。
location.pathname.substring(1)
I was wondering if it would be possible to get the page name from the address bar using jquery or javascript. I know this can be done using PHP but don't really want to as it is only a html website.
I.e. if the address is www.mywebsite.com/hello.htm
how do I get the hello.htm
part out of the address.
Thanks for any help you can provide.
解决方案
https://developer.mozilla.org/en/DOM/window.location
alert(location.pathname)
If you don't want the leading slash, you can strip it out.
location.pathname.substring(1)
这篇关于从地址栏获取页面文件名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!