JavaScript redirection can be done in 3 ways

Moderator: Lixas

blue-sky
Posts: 33
Joined: Tue Jun 12, 2007 3:41 pm

JavaScript redirection can be done in 3 ways

Post by blue-sky »

JavaScript redirection can be done in 3 ways:

1) Alert Redirect:

Code: Select all

<html>
<script>
alert("This page has been moved to a new location. **** OK to be redirected.");
location = "http://www.yoursite.com";
</script>
</html>


2) Confirm and Redirect:

Code: Select all

<html>
<script>
if(confirm("This page has been moved to a new location. Would you like to be redirected"))
{
location = "http://www.yoursite.com";
}
else
{
history.back();
}
</script>
</html>
3) Stealth Redirect:

Code: Select all

<html>
<script>
location = "http://www.yoursite.com";
</script>
</html>


Gyanu
Posts: 338
Joined: Mon Jul 30, 2007 2:03 pm
Contact:

Post by Gyanu »

no u r wrong it can b done in4 ways. The forth one is

[HTML]<meta http-equiv="Refresh" content="10;URL=yurpage" />[/HTML]

is it write?
Image
Lixas
Posts: 750
Joined: Wed Feb 16, 2005 4:21 pm

Post by Lixas »

i guess that is ok ;)
Image
Flipper3
Posts: 353
Joined: Tue Feb 28, 2006 12:34 am

Post by Flipper3 »

Yes, those are all ways to do it except for the alert no matter what they do they will be redirected. And secondly, you need to have:

Code: Select all

<script type="text/javascript">
instead of:

Code: Select all

<script>
And finally, it is best to not to use Javascript since there are quite a bit of users that disable Javascript. ;)
Lixas
Posts: 750
Joined: Wed Feb 16, 2005 4:21 pm

Post by Lixas »

if user is disabled JS, you can notice him by:

Code: Select all

<noscript>message for user when JavaScripts are disabled. HTML code is supported</noscript>
Image
Flipper3
Posts: 353
Joined: Tue Feb 28, 2006 12:34 am

Post by Flipper3 »

Lixas wrote:if user is disabled JS, you can notice him by:

Code: Select all

<noscript>message for user when JavaScripts are disabled. HTML code is supported</noscript>
Yeah, but then only the USER knows....not you.

Plus, you should want to make your website work for everybody. That's what Google does.
Gebbo
Posts: 554
Joined: Tue May 16, 2006 3:22 pm

redicted

Post by Gebbo »

Thanks for the tip i think i might use it for my site :P
.............................:: Spirit of Fire ::..................................

Image
Tails5
Posts: 1302
Joined: Wed Mar 15, 2006 8:09 am
Contact:

Post by Tails5 »

I use PHP redirecting usually, just [php]<?php Header("Location: http://www.the.other/url/");?>[/php]
Webmaster Yoda: You must confront the cPanel. Then, and only then, a webmaster will you be.
Julius Caesar: Veni, vidi, posti
Lixas
Posts: 750
Joined: Wed Feb 16, 2005 4:21 pm

Post by Lixas »

i guess it's the best way to redirect. but sometimes php is just not able to do that. so in this case JS will do the job
Image
Flipper3
Posts: 353
Joined: Tue Feb 28, 2006 12:34 am

Post by Flipper3 »

Lixas wrote:i guess it's the best way to redirect. but sometimes php is just not able to do that. so in this case JS will do the job
In what cases is PHP not able to do that?
Post Reply