Forum Moderators: open

Message Too Old, No Replies

Help please with a javascript function.

         

Simone100

6:20 am on Nov 18, 2006 (gmt 0)

10+ Year Member



Hello I need a javascript function that works something like this, but having trouble. Something like if http referrer is such and such a page then execute this script,
<BODY onLoad=window.setTimeout("location.href='http://www.website.com/test.php'",990)>

else void or null or however it is done.

Isn't http referrer the web page that is open? Help with this is grately appreciated.

Simone100

6:37 am on Nov 18, 2006 (gmt 0)

10+ Year Member



whoops, on the second sentence its supposed to be then "don't" execute the script, if a certain page is open.

RonPK

3:46 pm on Nov 18, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi Simone, here is an example with the onload-script in a
script
block.

<script type="text/javascript"> 
window.onload = function () {
if (document.referrer == "http://www.example.com/referring_page.html")
return;
else
window.setTimeout("location.href='http://www.website.com/test.php'",990);
}
</script>

edit: replace

document.referrer
by
location.href
if you want to test against the current page.

[edited by: RonPK at 3:49 pm (utc) on Nov. 18, 2006]

Simone100

2:26 am on Nov 19, 2006 (gmt 0)

10+ Year Member



Thank you very much, I'll try it, but before I do, having a hard time understanding what referring page means. Does that mean if this is the page thats open then set the setTimout? Please let me know, thanks Ron!

RonPK

2:28 pm on Nov 19, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The page the script runs on is not the referring page. Whether the script is inline or external does not matter.

The referring page is the page where the user clicked a link pointing to the current page.

Simone100

10:10 am on Nov 22, 2006 (gmt 0)

10+ Year Member



Man, you boys are amazing how easy you pick this stuff up. You write short instructions intricately and know exactly what they mean. I can read the same thing and my head is spinning trying to figure out how to use it! :)

I don't know if this will work, let me ask this......

If I tell page1 to refresh. Then I call page1 with page2. With no refresh command in page 2. Why does that always make page2 refresh as well? Can't I just make page 1 refresh somehow without making page 2 refresh as well? Or can't I just make part of a page refresh without the whole page refreshing? Please let me know someone, and then I'll know for sure if I might be able to make Rons code work.