简体   繁体   English

如何通过js启用/禁用浏览器历史记录

[英]How to Enable/Disable browser history through js

can we enable or disable browser history through java script code ?? 我们可以通过java脚本代码启用或禁用浏览器历史吗? If possible please tell me the mechanism to do this . 如果可能的话请告诉我这样做的机制。

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. 您可以尝试使用document.location.replace()它来清除历史记录中的最后一个条目,并将其替换为新URL的地址。

If the url or url-fragment changes, entries will be added to the browser history. 如果url或url-fragment更改,则条目将添加到浏览器历史记录中。 Means, the browser will display the navigation buttons. 意思是,浏览器会显示导航按钮。 When a user clicks them the previous url, or fragment is shown in the address bar. 当用户单击它们时,前一个URL或片段将显示在地址栏中。 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. 如果正在寻找一种没有历史记录和导航链接的单页应用程序行为,那么您不应该更改初始URL或其中的一部分。

This post can be helpful: How to clear browsers (IE, Firefox, Opera, Chrome) history using JavaScript or Java except from browser itself? 这篇文章可能会有所帮助: 如何使用JavaScript或Java清除浏览器(IE,Firefox,Opera,Chrome)历史记录,除了浏览器本身?

JS Frameworks like YUI suggest that we cannot remove the history items but you can do some other stuff with History. 像YUI这样的JS框架表明我们无法删除历史记录项,但您可以使用历史记录执行其他一些操作。 Excerpts from YUI docs - 摘录自YUI文档 -

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. 为此,请使用null或undefined添加或替换一个或多个值。

Refer this for more information http://yuilibrary.com/yui/docs/history/ 有关更多信息,请参阅此处http://yuilibrary.com/yui/docs/history/

if you need enable for history supported browsers there is Modernizr plugin you can use, Unsupported history browsers it will be disabled. 如果您需要启用历史记录支持的浏览器,可以使用Modernizr插件,不支持的历史浏览器将被禁用。

 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://developer.mozilla.org/en-US/docs/Web/Guide/API/DOM/Manipulating_the_browser_history

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM