Forum Moderators: open

Message Too Old, No Replies

Refresh Once

I.E problems

         

gameoverload

12:46 am on Dec 25, 2009 (gmt 0)

10+ Year Member



Firefox loads just fine, but in I.E. you need to refresh the page. I cant use a variable, but i can use anything else. I have tried many different scripts including the following with no success:

<script type="text/javascript">
function loaded()
{ if (!navigator.fudge) {
navigator.fudge = 1;
location.reload();
}}
</script>


<script language=" JavaScript" ><!--
function MyReload()
{
window.location.reload();
}
//--></script>

I have tried more, but dont want to take up the space. It needs to be done everytime the page is visited and automatically. Thanks in advance!

rocknbil

6:02 pm on Dec 25, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



So are you saying as soon as you hit the page, you want to reload it? I don't understand the logic, but this would cause a recursive loop using any inline variables. You will probably need to set a cookie to stop that, something like this.


<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01
Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<!-- doctype all on one line -->
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Untitled</title>
<script type="text/javascript">
window.onload=function() {
if (document.cookie!="reloaded=1") {
// using setTimeout to make sure it works,
// remove after testing.
var v = setTimeout('reloadWindow()',5000);
}
else {
document.getElementById('cookie-result').innerHTML=document.cookie;
}
}; // <-- not a typo
function reloadWindow() {
document.cookie="reloaded=1";
window.document.location.reload();
}
function clearCookie() {
if (document.cookie) { document.cookie="reloaded=''"; }
document.getElementById('cookie-result').innerHTML=document.cookie;
return false;
}
</script>
</head>
<body>
<p>Load the page. Wait 5 seconds. The cookie will say
&quot;reloaded=1&quot; below. Clear the cookie first to retest.
Remove the setTimeout if it is what you're after.</p>
<p> Testing: <span id="cookie-result">Cookie Result will appear here.</span></p>
<p>Added to clear the session cookie for retesting:</p>
<form action="" onSubmit="return clearCookie();">
<input type="submit" value="Clear Cookie">
</form>
</body>
</html>

gameoverload

7:08 pm on Dec 25, 2009 (gmt 0)

10+ Year Member



Thanks for the reply, i looked into a cookie and it is a great idea, i made a code based on the w3schools alerting tutorial, it works great, my only question is can i remove the cookie when you exit the page or after 1 minute i tried changing the it to a decimal but it didn't work
Here is the code:

<html>
<head>
<script type="text/javascript">
function getCookie(c_name)
{
if (document.cookie.length>0)
{
c_start=document.cookie.indexOf(c_name + "=");
if (c_start!=-1)
{
c_start=c_start + c_name.length+1;
c_end=document.cookie.indexOf(";",c_start);
if (c_end==-1) c_end=document.cookie.length;
return unescape(document.cookie.substring(c_start,c_end));
}
}
return "";
}
function setCookie(c_name,value,expiredays)
{
var exdate=new Date();
exdate.setDate(exdate.getDate()+expiredays);
document.cookie=c_name+ "=" +escape(value)+
((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}
function checkCookie()
{
username=getCookie('username');
if (username!=null && username!="")
{
document.write('page refreshed');
}
else
{
username="bob";
{
setCookie('username',username,365);
setTimeout("window.location.reload()",2000);
}
}
}
</script>
</head>
<body onload="checkCookie()">
</body>
</html>

Or if there is a code delete the cookie, but the page to delete the cookie would be in a different path that could work.

Thanks again! :)

gameoverload

12:13 am on Dec 26, 2009 (gmt 0)

10+ Year Member



Nevermind, I solved the problem, here is the code for those who wondered:
<head>
<script type="text/javascript">
function getCookie(c_name)
{
if (document.cookie.length>0)
{
c_start=document.cookie.indexOf(c_name + "=");
if (c_start!=-1)
{
c_start=c_start + c_name.length+1;
c_end=document.cookie.indexOf(";",c_start);
if (c_end==-1) c_end=document.cookie.length;
return unescape(document.cookie.substring(c_start,c_end));
}
}
return "";
}

function setCookie(c_name,value,expiredays)
{
var exdate=new Date();
exdate.setMinutes(exdate.getMinutes()+expiredays);
document.cookie=c_name+ "=" +escape(value)+
((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}

function checkCookie()
{
username=getCookie('username');
if (username!=null && username!="")
{
}
else
{
username="refresh";
{
setCookie('username',username,1);
setTimeout("window.location.reload()",1000);

}
}
}
</script>

</head>

<body onload="checkCookie()">