How to Enable/Disable browser history through js

纵饮孤独 提交于 2020-01-24 07:29:05

问题


can we enable or disable browser history through java script code ?? If possible please tell me the mechanism to do this .


回答1:


I think it is not possible.

Can you try using document.location.replace() it is used to clear the last entry in the history and replace it with the address of a new url.




回答2:


If the url or url-fragment changes, entries will be added to the browser history. Means, the browser will display the navigation buttons. When a user clicks them the previous url, or fragment is shown in the address bar. Your application can ignore it do something with it. If are looking for a single page app kind of behavior with no history and navigation links what so ever, then you should not change the initial url or part of it.




回答3:


This post can be helpful: How to clear browsers (IE, Firefox, Opera, Chrome) history using JavaScript or Java except from browser itself?

JS Frameworks like YUI suggest that we cannot remove the history items but you can do some other stuff with History. Excerpts from YUI docs -

While it's not possible to remove an entry from the browser history, it is possible to create a new entry (or replace the current entry) and remove one or more state values that were previously set. To do this, add or replace one or more values with null or undefined.

Refer this for more information http://yuilibrary.com/yui/docs/history/




回答4:


if you need enable for history supported browsers there is Modernizr plugin you can use, Unsupported history browsers it will be disabled.

 if (Modernizr.history) {
        //Code goes here that works if it's HTML 5 Browser with .history support? 
       //  I know some HTML5     browsers deal with .history oddly (read buggy) so what
       //   happens in      those cases?
     } else {
      // disable code
   }

check this link https://developer.mozilla.org/en-US/docs/Web/Guide/API/DOM/Manipulating_the_browser_history



来源:https://stackoverflow.com/questions/20046519/how-to-enable-disable-browser-history-through-js

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!