PDA

View Full Version : Test Browser Window Size


siphon
03-29-2006, 09:40 PM
i have this code to test the size of the users window and then load the proper HTML file for the size:


function redirectbyWidth(){
var smallpage = "http://www.yoursite.com/small";
var mediumpage = "http://www.yoursite.com/medium";
var largepage = "http://www.yoursite.com/large";

if (document.all){
cW=document.body.offsetWidth
if (cW <= 640) {
window.location.href = smallpage;
}
if (cW > 640 && cW <= 800) {
window.location.href = mediumpage;
} else {
window.location.href = largepage;
}
}
else
{
wW=window.outerWidth
if (wW <= 640) {
window.location.href= smallpage;
}
if (wW > 640 && cW <= 800) {
window.location.href= mediumpage;
} else {
window.location.href= largepage;
}
}
}

</script>
</head>

<body onload="redirectbyWidth()">
</body>
</html>


It works in IE but not FireFox. i believe it has something to do with "document.all" I have no idea what I’m doing here because I’m not Dreamweaver Capable. Is there a way around this by replacing the word with something else or do I have to rewrite the script some how?
Thnks for HELP!

siphon
03-31-2006, 03:05 PM
is there anything i can do to help my code work in both IE and FireFox ?

mrand01
03-31-2006, 08:23 PM
Firefox does not support document.all...not sure how to fix your problem though. I have a book by O'Reilly that I use for this kind of thing called Dynamic HTML...has like every HTML/DOM/JS command in it and tells you what browsers it works on.

sophistikat
03-31-2006, 08:33 PM
why are you worried about FireFox? the general internet public does not even know what FireFox is.

pkirsch
04-01-2006, 08:52 AM
Quite a lot of people use it!

sophistikat
04-01-2006, 05:32 PM
Quite a lot of people use it!yes but they are web developers, web designers, flash designers, flash programmers etc. etc. in my own research, the general public are my sisters, my wife, my parents, my friends, my wifes friends, my neighbors, my sisters friends, anyone who is not involved with the internet. These are the people who use IE because it came installed with their laptop or computer, use it because msn looks for IE first, if you want to update your windows from the microsoft website, you need IE and when asked about using others browsers for surfing the internet, 98% of them had no idea what firefox, netscape or opera were or that there are other browsers besides IE.

i think it more important to know who your audience are and unless you are making a tutorial or resource site, 9 out of 10 users are using IE...

...and these are my thoughts

EDIT: Browser Stats for the past 5 years (note the paragraph: Why so high Firefox figures?)
http://www.w3schools.com/browsers/browsers_stats.asp

pkirsch
04-01-2006, 06:02 PM
Hey thats true.lol

siphon
04-03-2006, 03:34 PM
Hey Thanks for your feedback on the matter.

So to bypass the whole FireFox ordeal can I add some code above the code i already have, So that if it Detects FireFox it goes to another webpage and ignores the code below it.. because for now if i put that code on my HTML then FireFox wont display anything.. just a blank page

any ideas ?

sophistikat
04-03-2006, 03:50 PM
here are some links:
http://www.java-scripts.net/javascripts/Detect-Browser.phtml
http://www.quirksmode.org/js/detect.html
http://www.netmechanic.com/news/vol3/javascript_no15.htm

full tutorial & tool
http://www.echoecho.com/jsbrowserdetection.htm
http://www.echoecho.com/toolbrowserredirect.htm

siphon
04-03-2006, 06:49 PM
Thank you , i'll let you know if i was able to get it done ;)

siphon
04-05-2006, 01:59 PM
is there a way of redirecting a page with out using the META tags? i just want to fit it inbetween my <script>

siphon
04-05-2006, 02:54 PM
ok if this is my code.


function redirectbyWidth(){
var smallpage = "http://www.yoursite.com/small";
var mediumpage = "http://www.yoursite.com/medium";
var largepage = "http://www.yoursite.com/large";

if (document.all){
cW=document.body.offsetWidth
if (cW <= 640) {
window.location.href = smallpage;
}
if (cW > 640 && cW <= 800) {
window.location.href = mediumpage;
} else {
window.location.href = largepage;
}
}
else
{
wW=window.outerWidth
if (wW <= 640) {
window.location.href= smallpage;
}
if (wW > 640 && cW <= 800) {
window.location.href= mediumpage;
} else {
window.location.href= largepage;
}
}
}

<----- THIS IS WHERE I WANT MY REDIRECT
</script>
</head>

<body onload="redirectbyWidth()">
</body>
</html>


can i put my redirect there? i want to do this b/c FireFox cant read that document.all code. i want it to at least redirect somewhere and not leave a blank page in FireFox browsers

sophistikat
04-05-2006, 03:34 PM
have you tried:function redirectbyWidth(){
var smallpage = "http://www.yoursite.com/small";
var mediumpage = "http://www.yoursite.com/medium";
var largepage = "http://www.yoursite.com/large";

if (document.all){
cW=document.body.offsetWidth
if (cW <= 640) {
window.location.href = smallpage;
}
if (cW > 640 && cW <= 800) {
window.location.href = mediumpage;
} else {
window.location.href = largepage;
}
}
else
{
wW=window.outerWidth
if (wW <= 640) {
window.location.href= smallpage;
}
if (wW > 640 && cW <= 800) {
window.location.href= mediumpage;
} else {
window.location.href= largepage;
}
}
} else
{
<----- THIS IS WHERE I WANT MY REDIRECT
window.location.href="http://www.yoursite.com/firefoxsucks.html";
}
</script>
</head>

<body onload="redirectbyWidth()">
</body>
</html>

siphon
04-05-2006, 04:29 PM
<script>
function redirectbyWidth(){
var smallpage = "http://www.location1.html";
var largepage = "http://www.location2.html";

if (document.all){
cW=document.body.offsetWidth
if (cW <= 2) {
window.location.href = smallpage;
}
if (cW > 2 && cW <=1024) {
window.location.href = smallpage;
} else {
window.location.href = largepage;
}
}
else
{
wW=window.outerWidth
if (wW <= 2) {
window.location.href= smallpage;
}
if (wW > 2 && cW <= 1024) {
window.location.href= smallpage;
} else {
window.location.href= largepage;
}
}
} else
{
window.location.href="http://www.location2.html";
}


thats my code and now it wont work :(

siphon
04-05-2006, 05:08 PM
once i added the code

} else
{
window.location.href="http://www.location2.html";
}

it does not work on IE or FireFox .. before i added the code it was working in IE but not FireFox... it would seem that the added code would have done the trick... but maybe it still registering it under document.all and FireFox wont read it :( WHy IS THIS SO HARD<><@<!#!#@!#@! @

sophistikat
04-09-2006, 10:01 PM
hows it going siphon? i did a little bit of research and here's and idea:
on your index page include only this script<html>
<head>
<title>Index Page</title>
<Script Language="JavaScript">
// Browserdetectionscript made by Henrik Petersen / NetKontoret
// Script explained at www.echoecho.com/javascript.htm
// Please do not remove this and the two lines above.
// Detect the browsername

browsername=navigator.appName;
if (browsername.indexOf("Netscape")!=-1) {
browsername="NS";
} else {
if (browsername.indexOf("Microsoft")!=-1) {
browsername="MSIE";
} else {
browsername="N/A";
}
};

//detect the browserversion
browserversion="0";
if (navigator.appVersion.indexOf("2.")!=-1) {browserversion="2"};
if (navigator.appVersion.indexOf("3.")!=-1) {browserversion="3"};
if (navigator.appVersion.indexOf("4.")!=-1) {browserversion="4"};
if (navigator.appVersion.indexOf("5.")!=-1) {browserversion="5"};
if (navigator.appVersion.indexOf("6.")!=-1) {browserversion="6"};

// Send visitor to relevant pages
// if netscape or firefox
if (browsername=="NS") {
window.location="http://www.mysite.com/ns.html";
};

// if IE
if (browsername=="MSIE") {
// if lowers then v4
if (browserversion<4) {
window.location="http://www.mysite.com/upgradeIE.html";
} else {
window.location="http://www.mysite.com/redirect.html";
}
}

// if name is not detect
if (browsername=="N/A") {
window.location="http://www.mysite.com/useIE.html";
};
</script>
</head>

<body>
</body>
</html>ns.html
setup this page explaining that firefox suck and they should use IE or Opera

upgrade.html
let them know that they are using an old version of the browser and they should upgrade to the latest version; provide them with the link and let them know that its free.

useIE.html
let them know that you could not recognize their browser and please use the latest version of IE or Opera.... but i'm not 100% sure of this option, it may work that you don't need to send them to this page??

redirect.html<body>
<title>Redirecting...</title>
<head>
<script>
function redirectbyWidth(){
var smallpage = "http://www.location1.html";
var largepage = "http://www.location2.html";

if (document.all){
cW=document.body.offsetWidth
if (cW <= 2) {
window.location.href = smallpage;
}
if (cW > 2 && cW <=1024) {
window.location.href = smallpage;
} else {
window.location.href = largepage;
}
}
else
{
wW=window.outerWidth
if (wW <= 2) {
window.location.href= smallpage;
}
if (wW > 2 && cW <= 1024) {
window.location.href= smallpage;
} else {
window.location.href= largepage;
}
}
}
</script>
</head>
<body>
</body>
</html>give that a shot and let me know how it goes
edit: source: http://www.echoecho.com/jsbrowserdetection02.htm