Forum Moderators: open

Message Too Old, No Replies

Is it possible to detect opera as Opera using javascript?

opera redirection

         

edward301

8:53 pm on Jun 4, 2004 (gmt 0)

10+ Year Member



I have a website that has content that only functions in internet explorer so i need to redirect all non ie webbrowsers to a different page.

I know there are plenty of javascripts out there that do that but they are all easily fooled when opera is given the browser id of MSIE6.

Does any one know of a java script that is not fooled by opera? If not should i be looking at a server side script like asp,php,cgi?

Bernard Marx

10:43 pm on Jun 4, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi edward301,

The

[blue]all[/blue]
collection is a surefire why of detecting IE (and only IE).
So:
[blue] var isIE = (document.all)? true : false[/blue]

Browser detection using user-agent strings is generally considered to be "a bad idea", to be avoided if poss. Testing for the existence of a particular feature is usually more to the point.

DrDoc

10:56 pm on Jun 4, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The all collection is a surefire why of detecting IE (and only IE).

Umm, no ;) Opera supports document.all as well
[opera.com...]

What you need to do is therefore something like:

if(document.all && navigator.userAgent.indexOf("Opera") == -1) {

}


has content that only functions in internet explorer

I bet you anything that can be made to work in the other browsers as well ;)

Bernard Marx

11:02 pm on Jun 4, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



X
The all collection is a surefire why of detecting IE (and only IE).

X
Oh bugger!

I bet you anything that can be made to work in the other browsers as well ;)

I do believe you're treading on thin ice there yourself, sir!

edward301

11:15 pm on Jun 4, 2004 (gmt 0)

10+ Year Member



The content is a streaming asx using an html gui with 3 layers.

firefox shows - Nothing! at all its just blank

opera displayes the gui but pushes the embeded media player over the top of it and also the stream wont load at all

Rambo Tribble

2:20 am on Jun 5, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Here is the user agent string provided by Opera 7.23 when in IE 6-spoofing mode (English language):

Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1) Opera 7.23 [en]

As you can see, "Opera" is in the string. This same string would be reported to a server script, as it is part of the HTTP request header and that's where JavaScript gets it, too.

To test any browser for the user agent string it returns, just run the following script in the browser (I used document.write() as it is easier to cut and paste the string in Opera, which won't allow c'n'p from an alert window):

<script type="text/javascript">
document.write(navigator.userAgent);
</script>

Bernard Marx

2:07 pm on Jun 6, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Scary browser stuff as usual.

Why it's considered acceptable for browsers to lie about themselves has long confused me. I'm surprised there aren't trademark issues involved. A new rule of thumb could be:
It's OK to use user-agent strings for detecting 'the underdog'
- IE won't be mentioning "Opera" in its string ...but for how long? After all, it used to pretend to be Netscape/Mozilla.

Anyways, I've just seen this in a script from www.twinhelix.com:

[blue]var isOp=window.opera?1:0;[/blue]

Unquibbleable (hopefully)

py9jmas

2:34 pm on Jun 6, 2004 (gmt 0)

10+ Year Member



Why it's considered acceptable for browsers to lie about themselves has long confused me

Why people insist on making web pages that only work on a subset of browser has long confused me.

I'm surprised there aren't trademark issues involved.

I believe Lynx's documentation used to warn that Netscape had threatened people whose browsers claimed to be Netscape with breach of copyright. The current version of Lynx just say some manufacturers may consider it `objectionable'.

Bernard Marx

3:35 pm on Jun 6, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'm not sure where that's directed. More often that not, user-agent strings are used to sniff out browsers so that they can be catered for in the best possible way, not to reject them.

Here, rejection (rather redirection) was the initial idea. In the real world that can't be helped sometimes. A line needs to be drawn somewhere - what do we do with Lynx? edward301 simply finds that the best way of catering for some browsers at the moment is to not give them stuff they'll choke on.

...but I do hate largely static pages that say "best viewed on..", that's just lazy - a declining occurence too.

RE Trademark: My lady is an IP lawyer, I'll have to ask her when she gets home.
[She'll just say: "Who knows until it's been tested in court"]

Purple Martin

2:17 am on Jun 7, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



There's a great browser sniffer in the "handy, generic javascript coding" thread. It identifies Opera even when it's spoofing. Look at message #18:
[webmasterworld.com...]

j4mes

12:22 am on Jun 8, 2004 (gmt 0)

10+ Year Member



> ...but I do hate largely static pages that say "best viewed on.."

Best one I ever saw was "Best viewed with eyes" :D

Think I'll stick it on a few of my own sites just to make a point!

encyclo

12:39 am on Jun 8, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Try: [opera.com...]

Also, I believe you can check the variable

window.opera
, which is true if the browser is Opera, and false otherwise.

Purple Martin

12:54 am on Jun 8, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



> ...but I do hate largely static pages that say "best viewed on.."
Best one I ever saw was "Best viewed with eyes" :D

My favourite is "Best viewed on my monitor at my house - come over if it looks bad where you are". Well at least it's honest :-P

j4mes

10:05 am on Jun 8, 2004 (gmt 0)

10+ Year Member



My favourite is "Best viewed on my monitor at my house - come over if it looks bad where you are". Well at least it's honest :-P

lol, brilliant :)