javascript - 如何使用 javascript 或 jQuery 删除或更改我的网址中的 .html 扩展名?

标签 javascript jquery html

<分区>

我的 html 页面网址是 www.example.com/training/product.html。我想将我的网址更改为 www.example.com/training/product。 strong> 是否可以使用 javascript 或 Jquery?如何?

最佳答案

抱歉,由于声誉限制,我无法发表评论。

正确的解决方案还没有在评论中。

window.history.replaceState()

完成任务。

我会这样做:

var link = 'www.example.com/training/product.html';
link.split('.html')[0];
window.history.replaceState( null, null, link );

要获得更受尊重的解决方案,请转到 How to reliably get the filename without the suffix in javascript?

链接:

https://developer.mozilla.org/en-US/docs/Web/Guide/API/DOM/Manipulating_the_browser_history#The_replaceState().C2.A0method

关于javascript - 如何使用 javascript 或 jQuery 删除或更改我的网址中的 .html 扩展名?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25397372/

相关文章:

jquery - 如何创建 jqGrid 上下文菜单?

html - 页脚不会到达底部,使用相对、绝对和内联 block ,不想使用 float

html - Rails ApplicationHelper 在没有返回语句的情况下转义 HTML

javascript - 更改动态创建的列表中单个元素的背景颜色

javascript - 用于移动设备的 Bootstrap pgwslideshow

javascript - 使用 Jquery 向 HTML 表添加记录

javascript - 从数组中删除一个对象并返回结果

javascript - 如果复选框被选中,获取下一个输入[文本]

javascript - IE8 中 indexOf for string 的备用函数是什么?

javascript - `Math.floor(a/a) == 1` 是否保证任何 `a` 使得 `a/a` 不是 NaN?