Problem with DTHML Browser detection/redirection

This is a discussion on "Problem with DTHML Browser detection/redirection" within the Web Page Design section. This forum, and the thread "Problem with DTHML Browser detection/redirection are both part of the Design Your Website category.



Go Back   Webforumz.com > Main Forums > Design Your Website > Web Page Design

Notices


Closed Thread
 
LinkBack Thread Tools
  #1 (permalink)  
Old Oct 15th, 2003, 12:24
New Member
Join Date: Oct 2003
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Problem with DTHML Browser detection/redirection

I'm trying to get this DHTML browser detection redirection script to work for
MSIE browsers >= 6 and Netscape Browsers >= 6. I am using MSIE 6 and Netscape 7.1 to test
these scripts under these conditions.

This is the original script, which is to be placed in the head section of the html document:

<script>

//Browser redirect Script- Dynamic Drive (www.dynamicdrive.com)
//For full source code, 100's more DHTML scripts, and Terms Of Use,
//visit dynamicdrive.com

var browser_type=navigator.appName
var browser_version=parseInt(navigator.appVersion)

//if NS 6
if (browser_type=="Netscape"&&browser_version>=5)
window.location.replace("http://mozilla.org")
//if IE 4+
else if (browser_type=="Microsoft Internet Explorer"&&browser_version>=4)
window.location.replace("http://microsoft.com")
//if NS4+
else if (browser_type=="Netscape"&&browser_version>=4)
window.location.replace("http://www.netscape.com")
//Default goto page (NOT NS 4+ and NOT IE 4+)
else
window.location="http://www.dynamicdrive.com"
</script>






This actually works. But when I change it to this...

<script>

//Browser redirect Script- Dynamic Drive (www.dynamicdrive.com)
//For full source code, 100's more DHTML scripts, and Terms Of Use,
//visit dynamicdrive.com

var browser_type=navigator.appName
var browser_version=parseInt(navigator.appVersion)

//if NS 6
if (browser_type=="Netscape"&&browser_version>=6) // Changed from >=5 to >= 6
window.location.replace("http://mozilla.org")
//if IE 4+
else if (browser_type=="Microsoft Internet Explorer"&&browser_version>=6) // Changed from >=4 to >=6
window.location.replace("http://microsoft.com")
//if NS4+
else if (browser_type=="Netscape"&&browser_version>=4)
window.location.replace("http://www.netscape.com")
//Default goto page (NOT NS 4+ and NOT IE 4+)
else
window.location="http://www.dynamicdrive.com"
</script>




... The first test condition goes to www.netscape.com (not mozilla.org) and the second test condition goes to the last condition (dynamicdrive.com)


Am I doing something wrong here? How do I get Netscape browsers >=6 and MSIE browsers >= 6 to go to the specified locations?


Thanks!

  #2 (permalink)  
Old Oct 15th, 2003, 14:53
Reputable Member
Join Date: Aug 2003
Location: United Kingdom
Posts: 158
Thanks: 0
Thanked 0 Times in 0 Posts
Although you tested it with NS7.1, if you add the following line of code, you will see that your browser version is still version 5. This is why your script is not responding as you expect.

Code: Select all
var browser_type=navigator.appName
var browser_version=parseInt(navigator.appVersion)

alert(browser_type + "\n" + browser_version) // Add this line
HTH
u2o
  #3 (permalink)  
Old Oct 15th, 2003, 17:51
Most Reputable Member
Join Date: Jul 2003
Posts: 1,856
Thanks: 0
Thanked 0 Times in 0 Posts
Good reason! Is that because of the happy people over at netscape then?? How can you detect for their browser when it won't tell you it's real version??
  #4 (permalink)  
Old Oct 15th, 2003, 19:02
Reputable Member
Join Date: Aug 2003
Location: United Kingdom
Posts: 341
Thanks: 0
Thanked 0 Times in 0 Posts
It's relatively basic as browser-sniffing goes. Try something a little more involved, or just write the code suitable for any browser.
Closed Thread

Tags
problem, dthml, browser, detectionredirection

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Browser detection IE mac jillcary JavaScript Forum 1 Aug 1st, 2007 11:28
Browser css problem saltedm8 Web Page Design 8 Aug 17th, 2006 13:04
Moock Detection Script Problem opel Flash & Multimedia Forum 0 Jan 18th, 2006 19:50
Browser size detection?! courtjester Web Page Design 1 Aug 26th, 2004 07:03
redirection problem iamzoli PHP Forum 12 Apr 11th, 2004 08:48


All times are GMT. The time now is 17:54.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43