如何在javascript或jquery中获取没有页面的当前URL [英] How to get current url without page in javascript or jquery
本文介绍了如何在javascript或jquery中获取没有页面的当前URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在Javascript或jQuery中获取没有页面的当前URL。
How can I get current URL without page in Javascript or jQuery.
例如,如果网址为:
http://www.abc.com/music/pop.aspx
我想获得没有页面的完整路径,如下所示:
I want to get the full path without the page so like:
不需要担心参数。
谢谢
推荐答案
你可以用< a href =https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/String/substring> substring()以提取网址的所需部分。
You can use substring() to extract the desired part of url.
Live Demo
urlBase = url.substring(0, url.lastIndexOf('/')+1);
您可以使用window.location.href获取当前网址
You can use window.location.href to get the current url
urlBase = location.href.substring(0, location.href.lastIndexOf("/")+1)
这篇关于如何在javascript或jquery中获取没有页面的当前URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文