Assigning to [removed].href without clobbering history

前端 未结 6 1225
渐次进展
渐次进展 2020-12-01 19:04

In testing document.location.href, I have observed that when the user initiates an action that results in javascript that assigns to document.location.href, the new URL is a

6条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-01 19:30

    Alas, your question can't be answered, AJAX requests have nothing to do with browser history, and if you loaded some dynamic content with them, then the user clicked the browser back button, the previous page is loaded (this which was loaded with an ordinary GET or POST request), which corrupts the sequence you display content in.

    Dmitri's answers means that you will maintain your own history for the dynamic content using the fragment part of the url (this after the # symbol), maybe you'll provide your own back and forward buttons, but still you're not protected from the effect of the browser back and forward buttons.

    If only they had provided some kind of events to handle user clicks on these buttons with the ability to cancel.

提交回复
热议问题