Showing a message to IE 5+ users (yes, the browser detection question again)

P

petermichaux

Hi,

I would like to display a message to Internet Explorer clients to
encorage them to get Firefox. Yes they may like Internet Explorer but
it is my site :)

http://www.explorerdestroyer.com/ uses navigator.userAgent

If ((ua.indexOf('msie') != -1) &&
(ua.indexOf('opera') == -1) &&
(ua.indexOf('webtv') == -1)) {
/* show message to IE users*/
}

I'm sure there is a better way to do this general detection. I vaguely
remember seeing a post with a huge long if conditional testing many
different objects to determine a very specific version of IE. I think
Richard Cornford wrote it. I just spent an hour (literally!) searching
the archives and couldn't find the post unfortunately. It may have been
along the lines of the following but very extended.

if (window.ActiveXObject &&
document.all) {
/* show message to IE users*/
}

I wish I had bookmarked that post because I am generally curious to
learn more about different versions of Internet Explorer and which
features distinguish it.

I would like to detect IE 5 and newer. Any suggestions or anyone know
about this post?

Thank you,
Peter
 
A

ASM

(e-mail address removed) a écrit :
Hi,

I would like to display a message to Internet Explorer clients to
encorage them to get Firefox. Yes they may like Internet Explorer but
it is my site :)

in header's javascript :

var IE = false; /*@cc_on IE = true; @*/
if(IE &&
confirm('Be careful you don't use correct browser !\n'+
'Won't you try to get the most out of the Web ?\n'+
'FireFox is for you'))
window.open('http://www.mozilla.com/firefox/');


or in the page :

<div style="display:none" id=IE>
<h1>Be careful you don't use correct browser !</h1>
<h2>Won't you try to get the most out of the Web ?</h2>
<p><a href="http://www.mozilla.com/firefox/" target="_blank">
FireFox is for you</a></p>
</div>
<script type="text/javascript">
var IE = false; /*@cc_on IE = true; @*/
if(IE) document.all['IE'].style.display='block';
</script>


nota :
/*@cc_on IE = true; @*/
detect all IEs even IE Mac
@cc_on ... @
is code in exclusive M$ script !
hidden to other browsers with /* ... */
 
P

petermichaux

Hi ASM,
var IE = false; /*@cc_on IE = true; @*/
/*@cc_on IE = true; @*/
detect all IEs even IE Mac
@cc_on ... @
is code in exclusive M$ script !
hidden to other browsers with /* ... */

This is very cool. What does @cc_on ... @ mean? @ is some special
thing? Do those letters cc_on stand for something meaningful?

It successfully detects IE 4, IE 5, IE 5.5, IE 6 on XP and IE 5 on OSX.
It also leaves the IE var false for Opera 8.5, Opera 9, Firefox 1.5 on
XP and Opera 9, Safari 1.3, Safari 2, Firefox 1.0, Firefox 1.5 on OS X.

Do you know if this will continue to work in IE 7?

Thank you,
Peter
 
R

Randy Webb

(e-mail address removed) said the following on 9/25/2006 1:02 AM:
Hi ASM,



This is very cool. What does @cc_on ... @ mean? @ is some special
thing? Do those letters cc_on stand for something meaningful?

Conditional Comment
It successfully detects IE 4, IE 5, IE 5.5, IE 6 on XP and IE 5 on OSX.
It also leaves the IE var false for Opera 8.5, Opera 9, Firefox 1.5 on
XP and Opera 9, Safari 1.3, Safari 2, Firefox 1.0, Firefox 1.5 on OS X.

Do you know if this will continue to work in IE 7?

Yes, Conditional Comments still work in IE 7.
 
A

ASM

(e-mail address removed) a écrit :

Hi peter,
This is very cool. What does @cc_on ... @ mean? @ is some special
thing? Do those letters cc_on stand for something meaningful?

@cc_on starts Jscript language (Jscript statement)
It successfully detects IE 4, IE 5, IE 5.5, IE 6 on XP and IE 5 on OSX.
It also leaves the IE var false for Opera 8.5, Opera 9, Firefox 1.5 on
XP and Opera 9, Safari 1.3, Safari 2, Firefox 1.0, Firefox 1.5 on OS X.

Do you know if this will continue to work in IE 7?

No reason it will not.
because, as I said, there you speak Jscript (M$ javascript) unknown by
other browsers.

ask to google : @cc_on

http://ns7.webmasters.com/caspdoc/html/jscript_cc_on_statement.htm
<http://msdn.microsoft.com/library/d...html/1e9b3876-3d38-4fd8-8596-1bbfe2330aa9.asp>
 
R

Randy Webb

ASM said the following on 9/25/2006 7:48 PM:
(e-mail address removed) a écrit :

Hi peter,


@cc_on starts Jscript language (Jscript statement)

No, it doesn't. To quote your own resource:

<quote>
The @cc_on statement activates conditional compilation in the scripting
engine.
</quote>

It does not start JScript language.
 
A

ASM

Randy Webb a écrit :
ASM said the following on 9/25/2006 7:48 PM:

No, it doesn't. To quote your own resource:

<quote>
The @cc_on statement activates conditional compilation in the scripting
engine.
</quote>

It does not start JScript language.

No it starts french ?
 
R

Randy Webb

ASM said the following on 9/25/2006 10:44 PM:
Randy Webb a écrit :

No it starts french ?

Something like that, but it sure as heck doesn't "starts Jscript language".
 
R

RobG

Randy said:
ASM said the following on 9/25/2006 10:44 PM:

Seems to me that wherever dates are inserted into news messages that
the timeszone should be included. If other posters insert similar
unqualified data, I expect the times as represented in text to be out
of sync with the actual flow of events.

Perhaps you could add a timezone? That might also give a hint on how
to interpret the date where the day date value is less than 13 - an ISO
format would reduce confusion further.
 
P

petermichaux

ASM said:
(e-mail address removed) a écrit :

var IE = false; /*@cc_on IE = true; @*/

I have added a couple other conditions for detecting IE and they seem
to work in IE4+ and Mac IE5. Currently I have in the head element of my
document...

TryFirefox.isIE = false; /*@cc_on TryFirefox.isIE = true; @*/
if (!(TryFirefox.isIE &&
typeof window.ActiveXObject === 'function' &&
typeof document.all === 'object' &&
typeof document.parentWindow === 'object')) {
TryFirefox.isIE = false;
}

Any suggestions for things I could add to this list detect IE?

Thank you,
Peter
 
R

Randy Webb

(e-mail address removed) said the following on 9/26/2006 1:46 AM:
I have added a couple other conditions for detecting IE and they seem
to work in IE4+ and Mac IE5. Currently I have in the head element of my
document...

TryFirefox.isIE = false; /*@cc_on TryFirefox.isIE = true; @*/
if (!(TryFirefox.isIE &&
typeof window.ActiveXObject === 'function' &&
typeof document.all === 'object' &&
typeof document.parentWindow === 'object')) {
TryFirefox.isIE = false;
}

Any suggestions for things I could add to this list detect IE?

I don't claim this list as mine, it isn't. It may be complete, it may
not be, but it shows what you can test for in a Conditional Compilation
in JScript:

@_win32 True if running on a Win32 system.
@_win16 True if running on a Win16 system.
@_mac True if running on an Apple Macintosh system.
@_alpha True if running on a DEC Alpha processor.
@_x86 True if running on an Intel processor.
@_mc680x0 True if running on a Motorola 680x0 processor.
@_PowerPC True if running on a Motorola PowerPC processor.
@_jscript Always true.
@_jscript_build
Contains the build number of the JScript scripting engine.
@_jscript_version
Contains the JScript version number in major.minor format.

So you could test to see if it is win16, win32 or a mac. And point them
to the appropriate Firefox page (Mac or IE)
 
R

Randy Webb

RobG said the following on 9/26/2006 12:33 AM EST:
Seems to me that wherever dates are inserted into news messages that
the timeszone should be included.

I don't agree with that. The time zone is - typically - included the
Headers of an article.
If other posters insert similar unqualified data, I expect the times
as represented in text to be out of sync with the actual flow of events.

The newsreader displays them based on the timestamp in the headers, not
in any time/timezone in the message.
Perhaps you could add a timezone? That might also give a hint on how
to interpret the date where the day date value is less than 13 - an ISO
format would reduce confusion further.

I could, but I don't see any benefit to it. But, it's added, for what
it's worth.
 
P

petermichaux

Randy said:
(e-mail address removed) said the following on 9/26/2006 1:46 AM:

I don't claim this list as mine, it isn't. It may be complete, it may
not be, but it shows what you can test for in a Conditional Compilation
in JScript:

@_win32 True if running on a Win32 system.
@_win16 True if running on a Win16 system.
@_mac True if running on an Apple Macintosh system.
@_alpha True if running on a DEC Alpha processor.
@_x86 True if running on an Intel processor.
@_mc680x0 True if running on a Motorola 680x0 processor.
@_PowerPC True if running on a Motorola PowerPC processor.
@_jscript Always true.
@_jscript_build
Contains the build number of the JScript scripting engine.
@_jscript_version
Contains the JScript version number in major.minor format.

So you could test to see if it is win16, win32 or a mac. And point them
to the appropriate Firefox page (Mac or IE)

Hi Randy,

Thanks. It seems that http://getfirefox.com will determine the users
operating system by navigator.userAgent. And I suppose if someone is
going out of there way to spoof userAgent they know enough to get
Firefox.

Peter
 
R

Richard Cornford

Thanks. It seems that http://getfirefox.com will determine
the users operating system by navigator.userAgent. And I
suppose if someone is going out of there way to spoof
userAgent they know enough to get Firefox.

That is a pathetic excuse for doing something that has no technical basis
whatsoever, and it doesn't take into account that numerous browsers use
default UA strings that are indistinguishable from those of IE, or that
browsers built around embedded IE may not reveal that in their default UA
string.

But on the whole bothering a user about their choice of browsers is as
bad when it is encouraging people not to use IE as it is when its "this
site is optimised for IE". Systems can be designed to be viable for all
the browsers that are likely to visit it, and for the public internet any
other thinking reveals limitations on the part of the author not on the
part of some browser(s).

Richard.
 
P

petermichaux

Richard said:
But on the whole bothering a user about their choice of browsers

I think the majority of IE users didn't choose IE. They don't even know
there are options. On some websites it is not a bad idea to give users
a tip that Firefox (or another) is worth looking at as an alternative.
is as
bad when it is encouraging people not to use IE as it is when its "this
site is optimised for IE". Systems can be designed to be viable for all
the browsers that are likely to visit it, and for the public internet any
other thinking reveals limitations on the part of the author not on the
part of some browser(s).

Of course even if IE was brought down to 10% we would still have to
make websites work on IE. Not having to program for IE isn't my
motivation since IE will not be disappearing soon. An informative
banner suggesting Firefox that only appears to IE users could turn some
people on to a better browser option.

Peter
 
V

VK

I think the majority of IE users didn't choose IE. They don't even know
there are options. On some websites it is not a bad idea to give users
a tip that Firefox (or another) is worth looking at as an alternative.

You can use this combo check (using both script type attribute and IE's
conditional compilation statements):

<html>
<head>
<title>Combo check</title>
<meta http-equiv="Content-Type"
content="text/html; charset=iso-8859-1">

<script type="text/javascript">
var message = '';
</script>

<script type="text/Jscript">
/*@cc_on @*/
/*@if (@_jscript)
message = 'You are using Internet Explorer.\n'
+ 'With full respect to your choice I would like '
+ 'to suggest some useful alternatives: ...';
@else @*/
message = 'Your browser pretends to be Internet Explorer '
+ 'and reports itself as such to servers. At the same time '
+ 'it is not really Internet Explorer, so spoofed server '
+ 'will probably serve a content this UA cannot handle.\n'
+ 'Do not be a liar and do not support liars!\n'
+ 'Here are some useful alternatives: ...';
/*@end @*/
</script>

<script type="text/javascript">
if (message) {
window.alert(message);
}
</script>

</head>

<body>

</body>
</html>
 
R

Richard Cornford

VK wrote:
/*@cc_on @*/
/*@if (@_jscript)
message = 'You are using Internet Explorer.\n'
+ 'With full respect to your choice I would like '
+ 'to suggest some useful alternatives: ...';
@else @*/
message = 'Your browser pretends to be Internet Explorer '
+ 'and reports itself as such to servers. At the same time '
+ 'it is not really Internet Explorer, so spoofed server '
+ 'will probably serve a content this UA cannot handle.\n'

This is a lie. The reason browsers spoof IE is because if the server
thinks they are IE it _probably_will_ serve them content they can
handle. And the reason Microsoft invented UA string spoofing was
because at the time pretending to be Netscape was the way of getting
servers to send content that IE could handle.
+ 'Do not be a liar and do not support liars!\n'

You like to give a lot of advice you don't follow yourself.

As the IE UA string is a lie itself (asserting as it does that the
browser is Netscape 4) it is difficult to see fault in others telling
the same lie. (Especially as the HTTP 1.1 definition of a user agent
header does not require it to have an meaningful/true content at all; a
statement cannot be untrue unless there a criteria for truth that can
be attached to it, which is not the case with UA headers)

Richard.
 
A

ASM

Randy Webb a écrit :
ASM said the following on 9/25/2006 10:44 PM:

Something like that, but it sure as heck doesn't "starts Jscript language".

begins speaking Jscript would-it be better ?

(and accepted !)

What you did quote forgives there are other conditional instructions by
the world (for instance JavaScript), and as it was told were are
speaking in Javascript what if not '@cc_on' could say to IE from now we
speak in Jscript ?
So in shortcut : that starts Jscript (instructions whom statement ...)
 
V

VK

Richard said:
This is a lie. The reason browsers spoof IE is because if the server
thinks they are IE it _probably_will_ serve them content they can
handle.

Like XSLT to Opera 8.x, right? ;-)
And the reason Microsoft invented UA string spoofing was
because at the time pretending to be Netscape was the way of getting
servers to send content that IE could handle.

I do not recall "mozilla" in HTTP.USER_AGENT string would be ever used
for a particular UA detecting. From NN2/IE2 that already was "isNN or
isIE or isSomeoneElse".

In some really old server-side scripts "mozilla" presence was used to
determine graphics enabled agents - thus able to render <img>'s and
table layouts, not text stream only (that was a revolutionnary feature
not yet supported by everyone).
This is why any graphics enabled agents adopted "mozilla" at the
beginning of the USER_AGENT string to pass the check successfully.
Please not that it was not a browser sniffing - that was exactly a
*feature check* based on the UA's string. That is a well past history
how, but as a remainder text-only UA's like Lynx still never have
"mozilla" in the USER_AGENT string: unless manually changed or cluessly
made.
As the IE UA string is a lie itself (asserting as it does that the
browser is Netscape 4)

Why exactly Netscape 4? Maybe it wants to pretent to be a Mozilla
prototype or Netscape 1 ? ;-)
it is difficult to see fault in others telling
the same lie.

With "mozilla" legacy it is not a spoofing of a particular UA and it
never was IMHO.
That's as I once said kind of the cross sign placed at the first line
of medieval manuscripts:
"Remembering the Greats who were before us... and now back to
business:..." :)

I see no correlation wih the situation when one currently existing UA
is actively pretending to be another currently existing UA by applying
mimicry not to USER_AGENT string only, but to the entire host
environment (while this host environment is far of being equal to the
spooffed one).

P.S. I really refuse to take a wannabe seriously if it starts its
"marked buttle" with a USER_AGENT string like "...MSIE...Internet
Explorer...like Gecko..." (no names, but these are real parts of a real
userAgent string). "Internet Explorer like Gecko" - sure, that's a hell
of serious competitor, I'll apply my best to support it. :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top