是否有一些方法来替换URL与JavaScript没有重新加载?例如window.history.replaceState()不工作,因为我期望
www.url.com/index.php/presenter/view/../
到
www.url.com/presenter/view/../
?我已经与history.replaceState功能尝试过,但它只是改变index.php
后的网址..
function parseUrl(){
currUrl = window.location.href;
verify = currUrl.indexOf("index.php");
if(verify != -1){
newUrl = currUrl.substring(0,verify-1);
newUrl += '#'+currUrl.substring(currUrl.indexOf('index.php')+10,currUrl.length);
if(window.history.replaceState){
window.history.replaceState(null, this.title, newUrl);
}
else{
window.location.href = newUrl;
}
}
}
你能展示你的代码吗?因为你只是在改变路径,所以这应该起作用。但请注意`replaceState`不是用于替换URL,而是用于替换当前的历史记录。如果使用`pushState`,用户将看到新的URL,但仍然可以使用后退按钮返回到前一个URL(在更改之前)。 – 2011-02-02 22:11:30
我需要所有链接ajax驱动,所以我改变window.location.hash在标准..但是例如RSS链接生成“正确”为index.php/...这是想要的行为,但我需要重定向英格利用户到网址的散列版本..我想不做重装(我只需要没有这些多余的参数,从estetic原因的URL) 我将代码添加到我的问题.. – simekadam 2011-02-02 22:35:11