How to refresh page without click refresh button?

JavaScript and client side scripting.

Moderator: General Moderators

loongest
Forum Commoner
Posts: 25
Joined: Wed Apr 07, 2004 12:23 pm

How to refresh page without click refresh button?

Post by loongest »

i need some help in php coding...
the problem i desire to solve is after i purchase and add cart...
the cart contain in main page will need refresh once..
how can i do it without using refresh button ?

thanks
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

there's

Code: Select all

<meta http-equiv=refresh content="5; url=http://blah.com">

and

<script language="javascript">document.location.href = "http://blah.com";</script>
there are others, but those are the basics..
loongest
Forum Commoner
Posts: 25
Joined: Wed Apr 07, 2004 12:23 pm

Post by loongest »

I'd like to thanks for comment feyd!

but i'm not very understand the statement ... :p
can u brief explain to me :)

<meta http-equiv=refresh content="5; url=http://blah.com">
and

<script language="javascript">document.location.href = "http://blah.com";</script>
evilMind
Forum Contributor
Posts: 145
Joined: Fri Sep 19, 2003 10:09 am
Location: Earth

Post by evilMind »

in php;

Code: Select all

header('Refresh: 7200'); // refresh every 2 hours
loongest
Forum Commoner
Posts: 25
Joined: Wed Apr 07, 2004 12:23 pm

Post by loongest »

i'm using pop up window to display new item with purchase
so how do i code in php if i click close pop up window and the mainpage get refresh ?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

<meta http-equiv=refresh content="5; url=http://blah.com">
normally goes in a page's header.. like this

Code: Select all

<html>
<head>
<!-- meta tags go in here -->
</head>
<body>
content appears here
</body>
</html>
the 'content' attribute contains 1 or more things. A timeout in seconds (in this case, 5 seconds), and an optional url value of where to redirect to. if the optional url is desired, a semicolon and 'url=' should appear after the timeout value. If the optional url is left out, the page will refresh itself at the specified time.

<script language="javascript">document.location.href = "http://blah.com";</script>
this can be placed pretty much anywhere in the html, however, the page will redirect to the specified address immediately when it's hit. If you wish to delay the time, like how the meta refresh works:

Code: Select all

<script language="javascript">setTimeout('document.location.href = "http://blah.com";',5000);</script>
this will also get called in 5 seconds, note that the time, is in milliseconds, not seconds.
loongest
Forum Commoner
Posts: 25
Joined: Wed Apr 07, 2004 12:23 pm

Post by loongest »

i'm using pop up window to display new item with purchase
so how do i code in php if i click close pop up window and the mainpage get refresh ?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

in the popup, use

Code: Select all

onunload="window.opener.location.href = window.opener.location.href"
or similar

edit: oops.. that should be onunload.
Last edited by feyd on Tue May 25, 2004 12:50 pm, edited 1 time in total.
loongest
Forum Commoner
Posts: 25
Joined: Wed Apr 07, 2004 12:23 pm

Post by loongest »

er..... where should i put this statement ?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

<body onunload="">
loongest
Forum Commoner
Posts: 25
Joined: Wed Apr 07, 2004 12:23 pm

Post by loongest »

onunload="window.opener.location.href = window.opener.location.href"

this statement means when the window is unload and ?? can u explain me the remain statement means ?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

when the window is closed, the code will be run.. the code tells the popup's creator to reload itself.
loongest
Forum Commoner
Posts: 25
Joined: Wed Apr 07, 2004 12:23 pm

Post by loongest »

so i add the statement on my pop up html with following code

<body onunload="onunload="window.opener.location.href = window.opener.location.href">

after i close the popup my mainpage will get refresh ? or just the popup page will get refresh on next time ?
evilMind
Forum Contributor
Posts: 145
Joined: Fri Sep 19, 2003 10:09 am
Location: Earth

Post by evilMind »

<body onunload="window.opener.location.href = window.opener.location.href">

and as long as the main page used window.open the main page will get refreshed when the user closes the popup window
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

more like

Code: Select all

<body onunload="window.opener.location.href = window.opener.location.href">
your main page, the page that created the popup, will get refreshed, or at least should.. you may need to fake it out a little bit.. as some browsers may not really refresh, since it's telling it to load the same page..
Post Reply