如何获取没有页面的网址

时间:2012-09-06 03:31:01

标签: javascript html string dom

我想要没有页面的网址。请在下面看到。

当前网址

http://localhost/FolderPath/Page.html

想要获得

http://localhost/FolderPath/

我该怎么做?感谢。

4 个答案:

答案 0 :(得分:1)

var oldPath = 'http://localhost/FolderPath/Page.html';
var newPath = oldPath.split('/').slice(0, -1).join('/') + '/';

答案 1 :(得分:1)

"http://localhost/FolderPath/Page.html".replace(/[^\/]*$/, '');

答案 2 :(得分:0)

var url = "http://localhost/FolderPath/Page.html";
url = url.substr(0, url.lastIndexOf('/') + 1);

答案 3 :(得分:0)

正则表达任何人?

var url = "http://localhost/FolderPath/Page.html";
url.match(/(.+)(\/(.+)?)$/)[1] + "/";

//returns "http://localhost/FolderPath/"

var url = "http://localhost/FolderPath/";
url.match(/(.+)(\/(.+)?)$/)[1] + "/";

//returns "http://localhost/FolderPath/"