/    Sign up×
Community /Pin to ProfileBookmark

help : redirect based on resolution, browser and platform

Hi,

I’m using the following script to redirect based on the browser and on the resolution of the screen:

<script type=”text/javascript”>

var w = screen.width;
var h = screen.height;
var browser = navigator.appName;

if((w == 800 && h == 600)&&(browser == “Netscape”)){
location = ‘page1’;
window.moveTo(0,0);
}else if((w == 800 && h == 600)&&(browser == “Microsoft Internet Explorer”)){
location = ‘page2’;
window.moveTo(0,0);
}else if((w == 1024 && h == 768)&&(browser == “Netscape”)){
location = ‘page3’;
window.moveTo(0,0);
window.resizeTo(w,h);
}else if((w == 1024 && h == 768)&&(browser == “Microsoft Internet Explorer”)){
location = ‘page4’;
window.moveTo(0,0);
window.resizeTo(w,h);
}

</script>

Now, I would like to double this code, taking in account the platform (mac or Windows) the client is running.
I’ve seen many coeds out there, but none that i seem to be able to implement with my code. (I’m a newbie).

Can you help ?

B

to post a comment
JavaScript

15 Comments(s)

Copy linkTweet thisAlerts:
@KravvitzSep 14.2006 — Do you really want to have to manage several versions of the same page?

What happens if someone is using a browser other than IE and Netscape?

I suggest you learn how to create [url=http://www.google.com/search?q=CSS+cross-browser+fluid+OR+liquid+layouts]cross-browser fluid/liquid layouts[/url].
Copy linkTweet thisAlerts:
@bxlbjornauthorSep 14.2006 — Let's say that it's a school project and we only have to make it work on those two browsers. On top of that i'm working on a mac, but they will view it on a PC.

So let's just start with the beginning :-)

Duplicating the pages for each browser/platform combination is not such a big deal actually. I just need to adjust height and with of some images, and voilà !

B
Copy linkTweet thisAlerts:
@KravvitzSep 14.2006 — Did your class teach you to use JavaScript to detect the browser or did you figure that out on your own?
Copy linkTweet thisAlerts:
@bxlbjornauthorSep 14.2006 — i started classes only two weeks ago and had only yesterday my first introduction to Javascript. Needless to say we haven't gotten as far as my question. But that doesn't stop me from finding out myself and learning ;-)
Copy linkTweet thisAlerts:
@LeeUSep 14.2006 — You need to read [URL=http://www.quirksmode.org/js/detect.html]this[/URL] Pay attention to the line at the beginning that says "Please read the object detection page first."
Copy linkTweet thisAlerts:
@slaughtersSep 14.2006 — ...a browser other than IE and Netscape?...[/QUOTE]Frankly, who cares if they are using Netscape? If you're locking your self into the two most popular browsers, then that would be IE and Firefox. Netscape is almost completly dead as a browser. http://www.thecounter.com/stats/2006/August/browser.php

But - it is much better to do object detection instead of browser detection: http://www.quirksmode.org/js/support.html
Copy linkTweet thisAlerts:
@KravvitzSep 15.2006 — Firefox's appName is set to "Netscape" by default.

I am well aware of those statistics. Firefox 1.5 happens to be my primary web browser.

I agree that object detection is better than user-agent or app-name detection.

However, like I said before, it's best to design pages to be cross-browser compatible and are fluid/liquid width.
Copy linkTweet thisAlerts:
@slaughtersSep 15.2006 — ....I agree that object detection is better than user-agent or app-name detection.

However, like I said before, it's best to design pages to be cross-browser compatible and are fluid/liquid width.[/QUOTE]
Like you said, if you design a page that uses object detection, then it is cross-browser compatible.

Personally, in the day to day practicle world, I really just don't bother too much. If it works in both Firefox and IE (via extensive use of getElementById), and degrades well in other browsers, then thats good enough for me. (I spend way too much time struggling with Firefox and IE based browser bugs allready)

Only when designing pages specifically for PDA's or Mobile phones do I pay attention to other browers, and there its best to do object detection, because there is no Firefox, Netscape or IE browser that works on most phones (the exception might be things like the TREO 700 smartphone that use Internet Explorer Mobile).

As far as I know - Opera is the only major browser that has attempted to seriously penetrate the mobile phone and PDA market - but it requires a Java enabled device to operate on.
Copy linkTweet thisAlerts:
@KravvitzSep 16.2006 — Like you said, if you design a page that uses object detection, then it is cross-browser compatible.[/QUOTE]
Using object detection does not excuse using JavaScript for something like this in my book.

Personally, in the day to day practicle world, I really just don't bother too much. If it works in both Firefox and IE (via extensive use of getElementById), and degrades well in other browsers, then thats good enough for me. (I spend way too much time struggling with Firefox and IE based browser bugs allready)[/QUOTE]
You don't even try for Opera and Safari?

What about IE5/Mac?
Copy linkTweet thisAlerts:
@slaughtersSep 21.2006 — Using object detection does not excuse using JavaScript for something like this in my book.[/QUOTE]That sentence made absolutly no sense. You don't even try for Opera and Safari?

What about IE5/Mac?[/QUOTE]
My information indicates that less than 3% of the Internet world use these. I personally expect that number to remain stable, or decrease slightly over time.

I'm more concerned about getting a handle on the new smart phone browsers. That's a market that I can see exploding rapidly in the next couple of years.
Copy linkTweet thisAlerts:
@bxlbjornauthorSep 22.2006 — That sentence made absolutly no sense. My information indicates that less than 3% of the Internet world use these. I personally expect that number to remain stable, or decrease slightly over time.

I'm more concerned about getting a handle on the new smart phone browsers. That's a market that I can see exploding rapidly in the next couple of years.[/QUOTE]


Well, I have a Mac myself wich would indicate I use Safari, but I dropped that quite fast to got back to FF .
Copy linkTweet thisAlerts:
@KravvitzSep 22.2006 — Using object detection does not excuse using JavaScript for something like this in my book.[/QUOTE]
That sentence made absolutly no sense.[/QUOTE]

I'll rephrase it then. In my opinion using object detection does not excuse that misuse of JavaScript.

My information indicates that less than 3% of the Internet world use these. I personally expect that number to remain stable, or decrease slightly over time.[/QUOTE]
I'd say it's closer to 4% for all 3 combined. Safari seems to have at least 2% market share.

I expect and hope that IE5/Mac use will decrease too.

I don't understand why you would choose to mostly ignore Macs but pay attention to browsers for handheld devices.
Copy linkTweet thisAlerts:
@slaughtersSep 22.2006 — ...I don't understand why you would choose to mostly ignore Macs but pay attention to browsers for handheld devices.[/QUOTE]Not MAC's - The MAC Internet Explorer browser. The currently existing small number if MAC IE browers (under 1%?) will continue to shrink overtime as they migrate to browsers like Firefox.

Handheld smartphones are brand new to the browser market and their growth potential is huge.
Copy linkTweet thisAlerts:
@KravvitzSep 22.2006 — So you don't ignore Safari? What you said seemed to imply that.
Copy linkTweet thisAlerts:
@slaughtersSep 22.2006 — I've said more than a few times what I consider important in terms of browser support.

I'll try one more time: Supporting IE and Firefox covers about 95%-97% of the world. I worry more about the potential from the smartphone market than I do about supporting the aging browser markets. None of this is rocket science.

Disagree all you want.
×

Success!

Help @bxlbjorn spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.11,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,
)...