如何在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:

http://www.abc.com/music/

不需要担心参数。

谢谢

你可以用 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)