PDA

View Full Version : Resolution/Browser Filter


cg9com
10-25-2002, 05:16 AM
Im doing a small filter.
Internet Explorer and 800x600 screen resolution should be the only ones to get to the "home.html" the rest should be taken to "fail.html"

however when i view through opera, with 800x600 screen resolution, it takes me to "home.html" anyway, i know this is a simple problem, can anyone help me come up with a solution as to why it wont filter correctly? im not the best javascript programmer.


if (document.all&&screen.width==800)
window.location.replace("home.html")
else
window.location.replace("fail.html")


i also tried with a function


function check () {
if (document.all&&screen.width==800)
window.location.replace("home.html");
}else{
window.location.replace("fail.html");}

....onLoad="check();"


with no luck, it must be the code?

glenngv
10-25-2002, 06:16 AM
I know Opera has function that enables users to set their browser to act as IE. Maybe this setting is checked. I think it's in the File menu.

cg9com
10-25-2002, 04:07 PM
so i cannot succesfully filter opera browsers?
the page it takes you to will let you into the website via link if you are using it.

but my webpage looks like total crap in it, i dont like opera

mordred
10-26-2002, 12:48 AM
The problem in your code is in fact that Opera also incorparted some aspects of other browser's js engines, in this case the IE proprietary document.all syntax. That's why it passes your check.
While it is true that Opera can mask itself to resemble another browser, the user agent string still leaves a detectable trace of it's real origin:

Mozilla/4.0 (compatible; MSIE 5.0; Windows 2000) Opera 6.0 [en]

That's what navigator.userAgent looks like in Opera 6.0 when set to identify as MSIE5.0. So you just have to look up if the value "opera" is contained in the user agent string.

There is a second, more convenient way: Since Opear 4.0 (IIRC) the js engine of opera exposes a property of the window object named opera. You can retrieve it simply by:

alert(window.opera);

Here's a small snippet that you can use to test if Opera gets detected. It performed correctly on my machine and should illustrate how detecting for opera is coded:


var firstTest = new Boolean(window.opera);
var secondTest = (navigator.userAgent.toLowerCase().indexOf("opera") > -1);

alert( "testing window.opera: " + firstTest +
"\nTesting userAgent: " + secondTest);

cg9com
10-26-2002, 04:20 AM
thank you for the help :)