OT: Script question

I have the following code that works to a point: // discover if browser is crappy Opera or crappy Safari str=navigator.userAgent; // Agent is unique for our purposes var sf=str.indexOf("Safari"); // found if browser is Chrome or Safari var ch=str.indexOf("Chrome"); // not found if browser is Safari var op=str.indexOf("Opera"); // unique for Opera var opt=1; // alternate shown below but not used ovar=window.opera; // is undefined if browser is not Opera if (!ovar) { opt=-1; } // unique for Opera // Safari gives sf=91,ch=-1; Opera gives sf=-1,op=7; Chrome gives sf=-1,ch>0. // Jump to different markup if crappy browser if (sf>0 && ch=0) { window.location.replace('Mobile.html'); } // ** NOTE treat crap as if mobile phone ** // Code is a one-pager; there are mobile phones that struggle and die with // message "Page too large" "open media site"

var isIE=str.indexOf("IE"); // not found in other browsers if (isIE>0) { window.location.replace('PCbase.html'); } var isMozilla=str.indexOf("Mozilla"); // Presumes in all variants; includes Netscape if (isMozilla>=0) { window.location.replace('PCbase.html'); } if (ch>=0) { window.location.replace('PCbase.html'); } // for Chrome

document.write(str+""); document.write("At this point, browser is not Safari, Chrome, Opera or IE or Mozilla"+""); // So, ASSuME we have mobile phone browser // window.location.replace('Mobile.html'); // -----^ always executes; previous valid .replace somehow bypassed

If i un-comment that last window.location.replace line, the proper execution of going to PCbase.html fails, and i get Mobile.html instead.

How can this be fixed?

Reply to
Robert Baer
Loading thread data ...

Wouldn't it be better if you can acquire the users client area size?

I gave up years ago trying to force users into using a small font and a minimum screen size, just to make my app look ok.

You need to quarry the screen data to make these choices.

Jamie

Reply to
Maynard A. Philbrook Jr.

you could use some elses between the ifs or a temporary variable, but the easiest is probably just to put it first!

window.location.replace('Mobile.html'); if (isIE>0) { window.location.replace('PCbase.html'); } if (isMozilla>=0) { window.location.replace('PCbase.html'); } if (ch>=0) { window.location.replace('PCbase.html'); } // for Chrome

javascript doesn't execute in parallell with the rest of the browser, the page doesn't reload until the script ends, so the last value of location wins.

--
umop apisdn 


--- news://freenews.netfront.net/ - complaints: news@netfront.net ---
Reply to
Jasen Betts

Quit screwing around. Go to school and get a copy of webkit to do the browser dependence reduction for you.

?-)

gives

with

Reply to
josephkk

Have no clue as how one can do that. Ideas?

Reply to
Robert Baer

That last time I did this I had a JS script to run on the client side which it then posted back information about needed things, like the screen object etc..

Some good reading here.

formatting link
and look here

formatting link

Jamie

Reply to
Maynard A. Philbrook Jr.

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.