PDA

View Full Version : Refresh page Script (mod)



Master-T
06-08-2007, 01:04 PM
Script Title: Refresh page Script

Script URL: http://www.dynamicdrive.com/dynamicindex6/refresh.htm

Is there a way to make this script go to another page rather than refreshing the current page?

mburt
06-08-2007, 01:24 PM
Switch the line:

window.location.reload()
with

window.open("newpage.htm","newWindow","width=500,height=500,left=5,top=30");
The width/height/left/top are just parameters to adjust the window settings.

//EDIT: Read post below :). I didn't know that location.replace() was a function, so use Twey's example. Sorry folks.

Twey
06-08-2007, 01:31 PM
What? That will (attempt to, and usually fail to due to popup blockers) open a new window. To navigate to another page, you would use:
location.replace("newpage.html");

Master-T
06-09-2007, 06:10 PM
Could you highlight each part of the code where I need to place that?

Thanks.

mburt
06-09-2007, 06:28 PM
<script language="JavaScript">

//Refresh page script- By Brett Taylor (glutnix@yahoo.com.au)
//Modified by Dynamic Drive for NS4, NS6+
//Visit http://www.dynamicdrive.com for this script

//configure refresh interval (in seconds)
var countDownInterval=60;
//configure width of displayed text, in px (applicable only in NS4)
var c_reloadwidth=200

</script>


<ilayer id="c_reload" width=&{c_reloadwidth}; ><layer id="c_reload2" width=&{c_reloadwidth}; left=0 top=0></layer></ilayer>

<script>

var countDownTime=countDownInterval+1;
function countDown(){
countDownTime--;
if (countDownTime <=0){
countDownTime=countDownInterval;
clearTimeout(counter)
window.location.replace("newpage.htm")
return
}
if (document.all) //if IE 4+
document.all.countDownText.innerText = countDownTime+" ";
else if (document.getElementById) //else if NS6+
document.getElementById("countDownText").innerHTML=countDownTime+" "
else if (document.layers){ //CHANGE TEXT BELOW TO YOUR OWN
document.c_reload.document.c_reload2.document.write('Next <a href="javascript:window.location.replace('newpage.htm')">refresh</a> in <b id="countDownText">'+countDownTime+' </b> seconds')
document.c_reload.document.c_reload2.document.close()
}
counter=setTimeout("countDown()", 1000);
}

function startit(){
if (document.all||document.getElementById) //CHANGE TEXT BELOW TO YOUR OWN
document.write('Next <a href="javascript:window.location.reload()">refresh</a> in <b id="countDownText">'+countDownTime+' </b> seconds')
countDown()
}

if (document.all||document.getElementById)
startit()
else
window.onload=startit

</script>

thetestingsite
06-09-2007, 06:29 PM
<script language="JavaScript">

//Refresh page script- By Brett Taylor (glutnix@yahoo.com.au)
//Modified by Dynamic Drive for NS4, NS6+
//Visit http://www.dynamicdrive.com for this script

//configure refresh interval (in seconds)
var countDownInterval=60;
//configure width of displayed text, in px (applicable only in NS4)
var c_reloadwidth=200

</script>


<ilayer id="c_reload" width=&{c_reloadwidth}; ><layer id="c_reload2" width=&{c_reloadwidth}; left=0 top=0></layer></ilayer>

<script>

var countDownTime=countDownInterval+1;
function countDown(){
countDownTime--;
if (countDownTime <=0){
countDownTime=countDownInterval;
clearTimeout(counter)
window.location.replace('newpage.html');
return
}
if (document.all) //if IE 4+
document.all.countDownText.innerText = countDownTime+" ";
else if (document.getElementById) //else if NS6+
document.getElementById("countDownText").innerHTML=countDownTime+" "
else if (document.layers){ //CHANGE TEXT BELOW TO YOUR OWN
document.c_reload.document.c_reload2.document.write('Next <a href="javascript:window.location.replace("newpage.html");">refresh</a> in <b id="countDownText">'+countDownTime+' </b> seconds')
document.c_reload.document.c_reload2.document.close()
}
counter=setTimeout("countDown()", 1000);
}

function startit(){
if (document.all||document.getElementById) //CHANGE TEXT BELOW TO YOUR OWN
document.write('Next <a href="javascript:window.location.replace("newpage.html");">refresh</a> in <b id="countDownText">'+countDownTime+' </b> seconds')
countDown()
}

if (document.all||document.getElementById)
startit()
else
window.onload=startit

</script>


The red highlighted part is the only one you really have to change; however, if you want the link in the phrase



Next refresh in 57 seconds


to go to the new page, then make the changes with the highlighted "blue" parts.

Hope this helps.

//EDIT: sorry Mike, cross posted.

Twey
06-09-2007, 08:19 PM
Er, using document.write() once the page has loaded will kind of break the page.

thetestingsite
06-09-2007, 08:21 PM
I thought it was odd as well, but that's the way the script is on DD.