Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/90.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript window.history.replaceState()未按预期工作_Javascript_Html - Fatal编程技术网

Javascript window.history.replaceState()未按预期工作

Javascript window.history.replaceState()未按预期工作,javascript,html,Javascript,Html,有没有办法不用重新加载就用JavaScript替换url?比如说 www.url.com/index.php/presenter/view/../ 到 ??我已经用history.replaceState函数尝试过了,但它只是在index.php之后更改url function parseUrl(){ currUrl = window.location.href; verify = currUrl.indexOf("index.php"); if(verify !=

有没有办法不用重新加载就用JavaScript替换url?比如说

www.url.com/index.php/presenter/view/../ 

??我已经用history.replaceState函数尝试过了,但它只是在
index.php
之后更改url

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;
        }
    }

}    
可以做到这一点,但大多数浏览器不支持(只有FF4和Chrome AFAIK)

GitHub正在为他们的应用程序使用它。

尝试使用-也许它对HTML5历史API的跨浏览器支持将解决您的问题

  • 更改应用程序的文件系统位置,使其反映所需的url:www.url.com/presenter/view/

  • 使用index.html shell

  • 默认情况下,将web服务器配置为打开index.html

  • 使用ajax获取数据并将其插入html文件


  • 你能出示你的密码吗?因为您只是在更改路径,所以这应该是可行的。但请注意,
    replaceState
    不是用于替换URL,而是用于替换当前历史记录条目。如果您使用
    pushState
    ,用户将看到新的URL,但仍然可以使用“后退”按钮返回到以前的URL(在您更改之前)。我需要所有链接都是ajax驱动的,因此我将按标准更改window.location.hash。但是,例如,RSS链接是作为index.php/“正确”生成的。。。这是我想要的行为,但我需要将incomig用户重定向到url的散列版本。我希望这样做而不需要重新加载(我只需要让url没有这些多余的参数,这是出于尊重的原因)我在我的问题中添加了代码。
    newUrl
    在你做了所有修改后是什么样子的?哦。.它现在正在工作。.显然,我真的不知道我让我的代码等一会儿,现在。.相当不错。.但你可能会提到有不好的增量(+10代替+11)…那是我的错误..所以谢谢,我现在将为我的网站的不那么积极的访问者祈祷。他似乎已经在使用API,但它对他来说并不正确。
    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;
            }
        }
    
    }