使用javascript更改URL链接而不刷新 [英] change URL link with javascript without refresh

查看:111
本文介绍了使用javascript更改URL链接而不刷新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在不刷新页面的情况下自动将url example.com/4000/title-2/#!4000更改为example.com/4000/title-2?基本上是从URL中删除/#!4000。
注意在hashbang之前删除/并不仅仅是hashbang很重要。

Is it possible to automatically change the url example.com/4000/title-2/#!4000 to example.com/4000/title-2 without to refresh the page ? Basically to remove "/#!4000" from the URL. Note that is important to remove the "/" before the hashbang not just the hashbang .

推荐答案

不知道是否这对你来说已经足够了,它是否完全可以跨浏览器工作...... chrome接受:

dont know if it is enough for you and whether it works completely cross-browser... chrome accepts:

location.hash = "";

但这会在地址栏中保留#

but this keeps the "#" in the address bar

window.history.replaceState('Object', 'Title', '/4000/title-2');

编辑:这不会改变浏览器的历史记录

this dies not change the history of the browser

编辑2:刚刚找到此stackoverflow资源

这篇关于使用javascript更改URL链接而不刷新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆