homepage Welcome to WebmasterWorld Guest from 54.204.58.87
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
webaster




msg:1481567
 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) {

window.history.go(0);
}
}

addEvent (window,'load', reloadOnceOnly)

//--></script>

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?

 

webaster




msg:1481568
 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;
window.location.reload();
}
}

//--></script>

This might work?

SpaceFrog




msg:1481569
 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 ...

webaster




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

have an example related to the given function?

Bernard Marx




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


if(window.location.search.indexOf('reload')<0)
window.location.replace(window.location.href+'?reload');

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


if(name!='reload')
{
name = 'reload';
window.location.replace(window.location.href);
}

kaled




msg:1481572
 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;
location.reload();
}}

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.

Kaled.

SpaceFrog




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

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

Thanks!

webaster




msg:1481574
 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;
location.reload();
}}

webaster




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

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

webaster




msg:1481576
 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
}
}
}

SpaceFrog




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

function loaded()
{ if (!navigator.fudge) {
navigator.fudge = 0;
}
navigator.fuge++;
if (navigator.fudge>1){navigator.fudge=0}
else{location.reload()};

}

webaster




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

explain what the function does?

is there need for event handler?

SpaceFrog




msg:1481579
 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 ...

webaster




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

[onlinetools.org...]

SpaceFrog




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

and?

webaster




msg:1481582
 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




msg:1481583
 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".

window.zum="hunh?";
alert(navigator.zum);

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

webaster




msg:1481584
 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

kaled




msg:1481585
 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.

Kaled.

Rambo Tribble




msg:1481586
 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.

kaled




msg:1481587
 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.

Kaled.

webaster




msg:1481588
 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




msg:1481589
 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




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

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

webaster




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

location.replace('URL')

not use window.location.replace

works in Opera 6-7?

works in IE 4->IE 6

need onload

kaled




msg:1481592
 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.

Kaled.

Rambo Tribble




msg:1481593
 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:

self.location.replace('URL');
this.location.replace('URL');
window.location.replace('URL');
location.replace('URL');

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.

webaster




msg:1481594
 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




msg:1481595
 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