javascript - 如何获取没有页面的url

标签 javascript html string dom

我想获取没有页面的url。请看下面。

当前网址

http://localhost/FolderPath/Page.html

想要得到

http://localhost/FolderPath/

我该怎么做?谢谢。

最佳答案

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

关于javascript - 如何获取没有页面的url,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12292585/

相关文章:

javascript - 交替点击

python - 计算一个字符串在多个字符串列中的出现次数

javascript - 在 WebStorm 中,我可以在 JSX 的 HTML 中禁用 JavaScript 关键字的完成吗?

javascript - 语法 : handleChange() function in React for different state attributes

javascript - 使用 MomentJS 从 JavaScript 发布到 C# 时出现日期解析问题

javascript - 访问多个参数

javascript - 如何通过 Javascript 使用鼠标事件在 Canvas 上绘图

html - 更改复选框位置

java - 如何构建带有 map 坐标的字符串?

java - 按列的内容对矩阵或二维数组进行排序