Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

location.reload problem

Status
Not open for further replies.

xenology

Programmer
May 22, 2002
51
0
0
US
Problem: why does location.reload not work unless there is an alert call right before the statement?

background on my page: a lot of extensive code that i don't want to make you sort through...ultimately, the page loads a table of work queue items. at the top is are drop down list boxes to filter the data. i'm wanting the onChange of the ddl's to refresh the page (individually) appending variable=xyz to the URL. that variable is used in the sql select to reduce/change the result set to display as work queue items.

the weird thing: it works as long as i have an alert statement between setting location.href and location.reload. if i comment out the alert statement it no longer works. why? i don't want to annoy the user poping up a box..."I'm gonna refresh your data".

anyone have any ideas?

Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "[URL unfurl="true"]http://www.w3.org/TR/html4/strict.dtd">[/URL]
<html>
<head>
</head>
<body>
just an example page...
<input type="text" id="myField" onChange="refreshPage();">
<script type="text/javascript">
function refreshPage(){
newLoc = parent.document.URL + "?variable="+document.getElementById("myField").value;
document.location.href = newLoc;
alert("hello world!");
document.location.reload(true);
}
</script>
</body>
</html>
 
Why would you want to call "reload" after setting location? Surely the page will reload anyway.

If it's cache-busting you're after, I'd append milliseconds since the epoch:

Code:
function refreshPage(){
   newLoc = parent.document.URL + '?variable=' + document.getElementById('myField').value;
   document.location.href = newLoc + '&rndNum=' + new Date().getTime();
}

Hope this helps,
Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
The next day it started working appropriately. It was moving to the page before the reload command so I went ahead and removed that line. Not sure what difference a day made but so far so good.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top