除了浏览器本身之外,如何使用 JavaScript 或 Java 清除浏览器(IE、Firefox、Opera、Chrome)历史记录?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2190808/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to clear browsers (IE, Firefox, Opera, Chrome) history using JavaScript or Java except from browser itself?
提问by Yogi
How to clear browsers (IE, Firefox, Opera, Chrome) history using JavaScript or Java, except clearing it from browser itself?
除了从浏览器本身清除之外,如何使用 JavaScript 或 Java 清除浏览器(IE、Firefox、Opera、Chrome)历史记录?
回答by Marc B
The document.location data in browsers is generally inaccessible to scripts, because allowing access would give any given site access to your entire browsing history. At most you can do a few simple manipulations, like "go to history entry #37" or "go back one page". But you can't do "what was the address of the page in history entry #23".
浏览器中的 document.location 数据通常无法被脚本访问,因为允许访问将使任何给定站点访问您的整个浏览历史记录。您最多可以进行一些简单的操作,例如“转到历史条目 #37”或“返回一页”。但是你不能做“历史条目#23 中页面的地址是什么”。
Most banking sites will use javascript links to prevent a click history from being built up. They'll do document.location.replace" to kill the last history entry (the current page) and replace it with the address of a new page. It in effect removes the "back" option to go back a page, because the previous page (as far as the browsing history is concerned) is now the new page.
大多数银行网站将使用 javascript 链接来防止建立点击历史记录。他们会执行 document.location.replace" 来杀死最后一个历史条目(当前页面)并将其替换为新页面的地址。它实际上删除了返回页面的“back”选项,因为前一个页面(就浏览历史而言)现在是新页面。
回答by kb.
In short it's not possible, sandboxing prevents browsers and the scripts/applets they run to modify or even create any files except for a few narrow cases. Javascripts and Java applets being allowed to clear other websites cookies or site content in your cache would not be desirable.
简而言之,这是不可能的,沙盒可以防止浏览器和它们运行的脚本/小程序修改甚至创建任何文件,少数情况除外。允许 Javascript 和 Java 小程序清除缓存中的其他网站 cookie 或网站内容是不可取的。
回答by Abhinay Reddy Keesara
There's no way a browser will let you clear its cache. It would be a huge security issue if that were possible
浏览器无法让您清除其缓存。如果可能的话,这将是一个巨大的安全问题
What you can do is to tell it not to cache your page, by sending the appropriate headers or using these meta tags:
您可以做的是通过发送适当的标头或使用这些元标记来告诉它不要缓存您的页面:
<meta http-equiv='cache-control' content='no-cache'>
<meta http-equiv='expires' content='0'>
<meta http-equiv='pragma' content='no-cache'>
I would like to point out that if you are working with sensitive data you should be using SSL. If you aren't using SSL, anyone with access to the network can sniff network traffic and easily see what your user is seeing.
我想指出的是,如果您正在处理敏感数据,则应该使用 SSL。如果您不使用 SSL,任何有权访问网络的人都可以嗅探网络流量并轻松查看您的用户所看到的内容。
Using SSL also makes some browsers not use caching unless explicitly told to. See this question.Will web browsers cache content over https
除非明确告知,否则使用 SSL 还会使某些浏览器不使用缓存。看到这个问题。Web 浏览器是否会通过 https 缓存内容
回答by Javan R.
But if you want to clear the actual page you can use:
但是如果你想清除实际页面,你可以使用:
$(function () {
//replace() does not keep the originating page in the session history,
document.location.replace("/Exercises#nocache"); // clear the last entry in the history and redirect to new url
});

