What does this code do?
Please forgive my ignorance but I am not very good at javascript. Could some kind soul explain what this code does please?
<html>
<head>
<title>Loading page...</title>
<meta http-equiv="refresh" content="1;URL=http://site1.com">
<script>
url='http://site1.com';
if(document.images) { top.location.replace(url); }
else { top.location.href=url; }
</script>
</head>
<body>Loading
<a href="http://site1.com">click here to continue</a>...
</body>
</html>
Thanks,
Jon
Busy posted this at 10:46 — 13th June 2007.
He has: 6,151 posts
Joined: May 2001
that line refreshes the page or redirects to that url every 1 second
benf posted this at 12:16 — 13th June 2007.
They have: 426 posts
Joined: Feb 2005
looks like the page keeps refreshing and replacing the url at the top with the same link??? Where did you get it. Why have you not run it to find out?
Good Value Professional VPS Hosting
Jon Lawrance posted this at 12:18 — 13th June 2007.
They have: 9 posts
Joined: Jan 2000
I can see that there is a refresh there, but once every second? Is that just to ensure it actually gets to site1.com just in case refresh doesn't get there the first time? I can't see the need for a repeated refresh.
Also, what does the "if(document.images) { top.location.replace(url); }" code do?
Busy posted this at 21:13 — 13th June 2007.
He has: 6,151 posts
Joined: May 2001
Short answer - nothing, it would never get to that part as the page would always refresh. You can't turn off meta tags.
Jon Lawrance posted this at 11:07 — 15th June 2007.
They have: 9 posts
Joined: Jan 2000
What would it do if there wasn't a refresh? I am curious because I wonder if it is for bots or something, to give them different information.
Greg K posted this at 12:27 — 15th June 2007.
He has: 2,145 posts
Joined: Nov 2003
The one thing every seems to be assuming is that this code is actually AT http://site1.com
Since that would be pointless, I myself assume this is a page located somewhere else, and this page is used to do nothing but redirect the visitor over to site1.com.
With that assumption, the page is just redundant to make sure you you get to site1.com. The javascript does a check to see which method the browser uses to change what URL you are visiting. Lastly, if the user doesn't want to wait the one second, and they have javascript disabled, there is a link they can click on to continue.
-Greg
Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.