Forum Moderators: open
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?
The
[blue]all[/blue] collection is a surefire why of detecting IE (and only IE). [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.
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 ;)
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>
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)
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'.
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"]
Also, I believe you can check the variable
window.opera, which is true if the browser is Opera, and false otherwise.