Window.history.replaceState () is not working as I expect

Is there a way to replace the javascript url without rebooting? for instance

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

to

www.url.com/presenter/view/../ 

? I tried it with the history.replaceState function, but it only changes the URL after 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;
        }
    }

}    
+3
source share
3 answers

Try using History.js - perhaps cross-browser support for the HTML5 history API will solve your problem.

+4
source

The HTML5 History API can do this, but is not supported by most browsers (only FF4 and Chrome AFAIK)

GitHub uses it for the tree slider .

+1
source
  • , URL-, : www.url.com/presenter/view/

  • index.html

  • - index.html

  • ajax, html .

0
source

Source: https://habr.com/ru/post/1789609/


All Articles