11

How to clear browsers (IE, Firefox, Opera, Chrome) history using JavaScript or Java, except clearing it from browser itself?

Andy E
  • 338,112
  • 86
  • 474
  • 445
Yogi
  • 197
  • 2
  • 4
  • 14
  • 4
    Man, would it be annoying if this was possible!? – Jørn Schou-Rode Feb 03 '10 at 09:20
  • Why would you ever need to be able to do that? – animuson Feb 03 '10 at 09:21
  • "How to clear browser history except clearing it from browser itself?" Can you be more specific? – rahul Feb 03 '10 at 09:21
  • Because from history, certain information will be viewed. For example, in any banking site if u surf then the index page only will get into browser's history and all other pages (after login pages) won't. – Yogi Feb 03 '10 at 09:50
  • best answer is here http://stackoverflow.com/a/14488769/218294. i.e. ajax and (initial) iframe urls are not stored in the history – Sam Watkins Jun 02 '15 at 07:28

4 Answers4

21

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".

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.

Marc B
  • 356,200
  • 43
  • 426
  • 500
2

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.

kb.
  • 1,955
  • 16
  • 22
2

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.

Using SSL also makes some browsers not use caching unless explicitly told to. See this question.Will web browsers cache content over https

Community
  • 1
  • 1
Abhinay Reddy Keesara
  • 9,763
  • 2
  • 18
  • 28
0

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
});
This is used by some banking websites
Umair Khan
  • 1,684
  • 18
  • 34
Javan R.
  • 2,011
  • 1
  • 19
  • 16