homepage Welcome to WebmasterWorld Guest from 54.205.189.156
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Subscribe to WebmasterWorld
Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

    
javascript redirect for just one browser + platform combination
browser sniffer for a specialized case
kelly001




msg:1478385
 1:06 am on Jan 19, 2003 (gmt 0)

Hi everyone,

I need a javascript that would allow when my page is loaded to automatically redirect all & only Mac users using IE5 to a different page. All other users would need to stay on the page they just loaded. Can someone help me out or point me towards a tutorial/script to do this?

 

tedster




msg:1478386
 3:25 am on Jan 19, 2003 (gmt 0)

This ought to do it.

1. First, I create a variable "agt", which sets the userAgent string to lower case.

2. The next line finds the starting position of the string "m-a-c" in the agent string. If that starting position is not equal to -1 (in other words, if the string is actually there) then the variable "is_mac" is set to a Boolean (true or false) value of "true".

3. Next, set another variable called "version" to be just the integer part of the navigator.appVersion string. This will truncate the decimal part of the version number.

4. Look to see if the string "m-s-i-e" appears in in the agt string (similar to step 2). If it's there (again, not equal to -1), then is_ie is set to "true".

5. Set a new variable to combine the "true or false" value of "is_ie" and the statement "version = 5". This gives us the "true or false" value for is_ie5. According tom Boolean operation, "is-ie5" will be true only if BOTH values are true.

6. The final step. If both "is_mac" and "is_ie5" are true, then replace the current location. I used the replace() method so that the user's Back Button will stay intuitive.

var agt=navigator.userAgent.toLowerCase();
var is_mac = (agt.indexOf("mac")!=-1);
var version = parseInt(navigator.appVersion);
var is_ie = (agt.indexOf("msie")!= -1);
var is_ie5 = (is_ie && (version = 5));

if (is_mac && is_ie5) {location.replace("alternate_page.html")}

kelly001




msg:1478387
 3:02 pm on Jan 19, 2003 (gmt 0)

thanks for the detailed explanation and please excuse my ignorance in this subject but how do I include this to my page?

Do I just put this in my head tag?

<script language=JavaScript>
var agt=navigator.userAgent.toLowerCase();
var is_mac = (agt.indexOf("mac")!=-1);
var version = parseInt(navigator.appVersion);
var is_ie = (agt.indexOf("msie")!= -1);
var is_ie5 = (is_ie && (version = 5));

if (is_mac && is_ie5) {location.replace("alternate_page.html")}
</script>

kelly001




msg:1478388
 4:27 pm on Jan 20, 2003 (gmt 0)

this worked for me, in case this can help anyone else out there in the future;

<script language="JavaScript">
if(navigator.appVersion.indexOf("MSIE 5.")!=(-1)
&& navigator.appVersion.indexOf("Macintosh")!=(-1)) {
top.location.href = "new-iframe-page.html";
}
</script>

Good luck.

tedster




msg:1478389
 5:03 pm on Jan 20, 2003 (gmt 0)

Yes, it can be condensed. The code I wrote was broken into bite sized pieces for easy understanding and future editing - hoping to help other people in similar but not identical situations.

kelly001, your code works, but it "breaks" the Back Button for your visitor. I'd suggest changing this line:

top.location.href = "new-iframe-page.html";

to read like this:

top.location.replace("new-iframe-page.html");

Glad you've got your solution.

kelly001




msg:1478390
 3:27 am on Jan 21, 2003 (gmt 0)

thank you very much, I hadn't noticed that... your little fix works wonders in that regards! thanks

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved