Change the URL in the browser without loading the new page using JavaScript

后端 未结 14 2224
忘掉有多难
忘掉有多难 2020-11-22 02:02

How would I have a JavaScript action that may have some effects on the current page but would also change the URL in the browser so if the user hits reload or bookmark, then

14条回答
  •  长情又很酷
    2020-11-22 02:42

    With HTML 5, use the history.pushState function. As an example:

    
    

    and a href:

    Click to change url to bar.html
    

    If you want to change the URL without adding an entry to the back button list, use history.replaceState instead.

提交回复
热议问题