homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

reload page once onload
reload refresh IE

 3:04 pm on Mar 8, 2005 (gmt 0)

The Code

<script language="JavaScript"><!--

var isIe = (navigator.appName == "Microsoft Internet Explorer");
function reloadOnceOnly() {
if (isIe) {


addEvent (window,'load', reloadOnceOnly)


I need to reload this page because IE in 3 of 4 cache settings fails to dsiplay the page properly - only IE cahce setting every time check for a new page works actually

Now it is looping - I want only once that the page reloads and best would be immediately reloadin it

How to do this?



 3:26 pm on Mar 8, 2005 (gmt 0)

<script language="JavaScript"><!--
var reloaded = false;
var isIe = (navigator.appName == "Microsoft Internet Explorer");
function reloadOnceOnly() {
if (isIe &&!reloaded) {
reloaded = true;


This might work?


 4:16 pm on Mar 8, 2005 (gmt 0)

if not on the onload when you reload page pass a parmeter in the link, the parse url and check if parameter is passed or not ...


 5:12 pm on Mar 8, 2005 (gmt 0)

have an example related to the given function?

Bernard Marx

 9:03 pm on Mar 8, 2005 (gmt 0)


Alternatively, I reckon Mr. Tribble would suggest using the window's name property, since this is preserved - this would leave the address bar untouched.

name = 'reload';


 10:08 am on Mar 9, 2005 (gmt 0)

Here's a trick I discovered recently.

If you want to store data without cookies for a single window, use the navigator object.

In this case you might use something like

function loaded()
{ if (!navigator.fudge) {
navigator.fudge = 1;

Data stored in the navigator object survives page transitions. However, it is not shared between windows.

This works in current versions of Firefox, IE and Opera, but I haven't tested it further.



 10:39 am on Mar 9, 2005 (gmt 0)

Kaled your code rocks!
I shall reward you with 500 grams of my highest estime!



 12:48 pm on Mar 9, 2005 (gmt 0)

In IE cache settings can invoke serious problems.

My DHTML suffers in IE a lot from the caching in IE. I need to relaod a page due to the cahcing in IE to display the page properly!

Is there anyway to avoid meta pragma, expired meta and use javascript
to affect the caching?

What is this actually?

function loaded()
{ if (!navigator.fudge) {
navigator.fudge = 1;


 1:07 pm on Mar 9, 2005 (gmt 0)

I need to reload the page each time the page is visited and only once


 1:15 pm on Mar 9, 2005 (gmt 0)

in my case I found out when removing the problematic page from the history list and visiting again the same page fixes the display probs how can I remove/overwrite the current page from the history list

some scripts that maybe usefull for other things

cancell events

function nullify(evt) {
if (!evt) evt = window.event; // define the event object for MSIE

if (evt) {
if (evt.preventDefault) {
evt.preventDefault(); // cancel the default event Opera, Mozilla
evt.stopPropagation(); // this will stop the method bubbling out
else {
evt.cancelBubble = false; // stop bubbling on MSIE
evt.returnValue = false; // cancel the default event MSIE


 1:26 pm on Mar 9, 2005 (gmt 0)

function loaded()
{ if (!navigator.fudge) {
navigator.fudge = 0;
if (navigator.fudge>1){navigator.fudge=0}



 1:45 pm on Mar 9, 2005 (gmt 0)

explain what the function does?

is there need for event handler?


 2:52 pm on Mar 9, 2005 (gmt 0)

All this function does is that it add a propriety to the navigator whiwh is not meant for that but it does work

so it assigns a value to this new navigator propriety and test it on the reload if the value is already assigned it does not reload the page ...


 4:12 pm on Mar 9, 2005 (gmt 0)



 4:16 pm on Mar 9, 2005 (gmt 0)



 4:38 pm on Mar 9, 2005 (gmt 0)

why use the word fudge?

did you test your code?

online example?

not worried it will execute when multiple onload are fired?

Rambo Tribble

 4:47 pm on Mar 9, 2005 (gmt 0)

The attachment of a new property to the navigator object should work, but there is reason for caution. How the object is implemented appears to vary between browsers, and if the property was actually a part of the navigator object one might think it should survive changing windows, though it would probably be necessary to make the property part of the object's prototype, since it would appear that each window is treated as an instace of the navigator object.

Running the following in IE or Moz yields an alert of "hunh?", while Opera generates a response of "undefined".


[edited by: Rambo_Tribble at 4:59 pm (utc) on Mar. 9, 2005]


 4:57 pm on Mar 9, 2005 (gmt 0)

other topic

is there away when leaving page 1 to go to page 2
the history gets the latest visted url of page 2 -to erase/replace it from the history when going back to page1


 6:52 pm on Mar 9, 2005 (gmt 0)

why use the word fudge?
did you test your code?

Fudge is a name I use when I need an identifier to perform some form of cheat.

I did not test the code. I suggested as a basic example of a trick to store information that needs to survive page transitions. I used it when creating some javascript for use in compiled html help (.chm files). Cookies don't work so I had to find an alternative. The basic technique worked, when I tested it, with IE, FF and Opera, however, I only needed it to work with IE due to the application.

Eventually, I dropped the code in favour of an alternative approach.


Rambo Tribble

 8:38 pm on Mar 9, 2005 (gmt 0)

Addendum: I find that the code snippet I posted sometimes produces the "hunh?" alert in IE and Moz, but is not consistent. No discernable pattern to this behavior has surfaced, though it may have to do with variations in object persistence and the originally observed behavior may be an artifact of such persistence, not reflective of the object's nature.

Update: The original results were an artifact of object persistence: when a property is assigned to the navigator object, it survives even a hard reload of the page.


 11:07 pm on Mar 9, 2005 (gmt 0)

when a property is assigned to the navigator object, it survives even a hard reload of the page.

It does more than that, it survives loading an entirely new page. If you wanted to, you could count the number of page transitions or implement your own history list, etc.



 11:52 pm on Mar 9, 2005 (gmt 0)

is it possible to say remove the current page that has loaded from the history as it ware remove the last entry - I need it badly because IE and Opera have problems when going back to the page - the page loads not properly only when that page is removed from the history list - when going back it loads properly

Rambo Tribble

 1:14 am on Mar 10, 2005 (gmt 0)

The property assigned to the navigator object did not survive reload on Opera; it only survived in Moz (1.7.5) and IE 6 (on Win XP Pro SP2).

Webaster, are you looking for the location.replace('URL') method? It loads a new URL which replaces the current page's entry in the history list.

Bernard Marx

 8:43 am on Mar 10, 2005 (gmt 0)

That's disappointing. It was sounding promising up till then.


 10:44 am on Mar 10, 2005 (gmt 0)


not use window.location.replace

works in Opera 6-7?

works in IE 4->IE 6

need onload


 10:50 am on Mar 10, 2005 (gmt 0)

My apologies..... I just checked and can confirm that the navigator trick does not work in Opera. However, it is possible that a similar bodge could be made to work.


Rambo Tribble

 2:43 pm on Mar 10, 2005 (gmt 0)

The location object is unique to each window, so within a given window's code execution environment, the following are equivalent:


When you need to preface the location object is when your code is acting on a window other the one the code is executing in. If you did this: var newWin=window.open("","",""); then you could do this: newWin.location.replace('URL');

The replace() method of the location object has been around since NN 3 and IE 4, don't know about when Opera started supporting it, but it has had it since 6, at least.

The method can be called either by the body onload event or by window.onload in a header script.


 3:38 pm on Mar 10, 2005 (gmt 0)

the replace('URL') method does it replace a URL in the addressbar or does it replace the last history entry with the given URL

Rambo Tribble

 4:26 pm on Mar 10, 2005 (gmt 0)

It replaces the history listing of the current page with that of the new page and loads the new page. In other words, the history entry of the page that calls location.replace() is lost, and that page can no longer be accessed with the back button.

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved