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

后端 未结 14 2242
忘掉有多难
忘掉有多难 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:43

    I was wondering if it will posible as long as the parent path in the page is same, only something new is appended to it.

    So like let's say the user is at the page: http://domain.com/site/page.html Then the browser can let me do location.append = new.html and the page becomes: http://domain.com/site/page.htmlnew.html and the browser does not change it.

    Or just allow the person to change get parameter, so let's location.get = me=1&page=1.

    So original page becomes http://domain.com/site/page.html?me=1&page=1 and it does not refresh.

    The problem with # is that the data is not cached (at least I don't think so) when hash is changed. So it is like each time a new page is being loaded, whereas back- and forward buttons in a non-Ajax page are able to cache data and do not spend time on re-loading the data.

    From what I saw, the Yahoo history thing already loads all of the data at once. It does not seem to be doing any Ajax requests. So when a div is used to handle different method overtime, that data is not stored for each history state.

提交回复
热议问题