Page Redirection

liunx

Guest
Hi!<br />
<br />
I have a problem. My homepage, what is under construction at the moment, is only viewable without errors with Explorer. I want to insert a javascript to the index.htm file, that redirects the visitors, depending on their browser.<br />
<br />
I am currently trying this:<br />
<br />
<script language=Javascript><br />
<br />
if ((navigator.appName=="Microsoft Internet Explorer")&(navigator.userAgent.indexOf("Opera")==-1)&(navigator.userAgent.indexOf("Netscape")==-1)&(navigator.userAgent.indexOf("Mozilla")==-1)){document.location.href=http://www.webdeveloper.com/forum/archive/index.php/"good.htm";}else{document.location.href="wrong.htm";}<br />
<br />
</script><br />
<br />
The indexOf stuff is needed, because Mozilla, Netscape and Opera would trick the script, because they make themselves look like Explorer.<br />
<br />
...But this still doesn't work right, because now this script redirect every browser to "wrong.htm" (even explorer). <br />
<br />
I would be very thankful, if somebody would help me out with a working script.<!--content-->Your & signs need to be &&<!--content-->1: Mozilla doesn't pretend to be IE. Don't know about the others<br />
2: You've put & when you need &&<!--content-->Mozilla pretends to be Netscape :). Try this:<br />
<!-- m --><a class="postlink" href="http://diitman.uw.hu/test/jo.htm">http://diitman.uw.hu/test/jo.htm</a><!-- m --><br />
<br />
this has<br />
<br />
<Script Language="JavaScript"><br />
<!--<br />
document.write (navigator.appName)<br />
//--><br />
</script><br />
<br />
in it. Try it with Mozilla, and it will show "Netscape".<br />
<br />
But back to the question:<br />
I tried as you told:<br />
<br />
<script language=Javascript><br />
<br />
if ((navigator.appName=="Microsoft Internet Explorer")&&<br />
(navigator.userAgent.indexOf("Opera")==-1)&&<br />
(navigator.userAgent.indexOf("Netscape")==-1)&&<br />
(navigator.userAgent.indexOf("Mozilla")==-1))<br />
{document.location.href=http://www.webdeveloper.com/forum/archive/index.php/"jo.htm";}else{document.location.href="rossz.htm";}<br />
<br />
</script><br />
<br />
But it does the same :(<!--content-->http://diitman.uw.hu/test/indulo.htm<br />
<br />
This is the page with the script. If it worked good, it would redirect you to a white page, with your browsers name (IE), if you view it with IE, and would redirect you to a blue page, if viewed with something else.<!--content-->if (navigator.appName=="Microsoft Internet Explorer") document.location.href=http://www.webdeveloper.com/forum/archive/index.php/"jo.htm"<br />
else document.location.href=http://www.webdeveloper.com/forum/archive/index.php/"rossz.htm"<!--content-->Originally posted by cijori <br />
1: Mozilla doesn't pretend to be IE. Don't know about the others<br />
2: You've put & when you need && <br />
The problem is IE pretends to be Mozilla. That's where his logic is breaking down.<!--content-->location = /microsoft/i.test(navigator.appName) && typeof window.opera == 'undefined' ? 'jo.htm' : 'rossz.htm';Opera is, by default, spoofed as IE. So you'll want to check for the existence of window.opera here as well.<br />
<br />
However, the "real" solution here is to get your site working correctly in all browsers.<!--content-->
 
Back
Top