HikksNotAtHome said:
You can do it, reliably, neither on the server nor in the
browser. Why does it matter what browser I am using?
I assume that was intended to start "you can not do it, . . . ".
The major problem is you are relying on an unreliable
string to attempt to determine the browser.
Not sure how to object test for ActiveX, never tried to.
And there is probably a browser besides IE that will pass
the following, but I am not sure:
Yes, Konqueror (so probably Safari), IceBrowser and Web Browser 2.0. In
fact I think that test probably only rules out Opera and Gecko browsers
as it seems to be common these days for non-IE browsers to be
implementing a document.all collection.
if (document.all && document.getElementById &! window.opera){
alert('You might be using IE')
}
<snip>
I would have thought that, since the desire is to call the ActiveXObject
constructor, the pertinent test would be for the existence of the
ActiveXObject constructor:-
if(window.ActiveXObject){
// new ActiveXObject can be called.
}
-or-
if(typeof ActiveXObject != 'undefined'){
// new ActiveXObject can be called.
}
Following the principal that you feature/object test as close to the
problem as possible.
However, with IceBrowser being an example of at least one browser that
has a fake ActiveXObject constructor it becomes very important to test
the object returned to ensure that it is an object. The OP's - if (w !=
null) - is a good start but it would also be worth checking that the
object has the methods and properties that the script wants to call (eg.
Documents.Open) in case the ActiveXObject constructor is a fake that
just returns a standard JavaScript object.
But then there are the ActiveX user preferences. My IE 6 will not allow
any scripting of ActiveX over the internet so even if it could be
determined by other means that the browser was IE 6 the script would
still not execute on it.
Just to add to the confusion, I recently read in a netscape.public.*
group of development work on ActiveX for windows Gecko browsers with a
new "GeckoActiveXObject" constructor. So maybe this script would not be
limited to just IE in the future. Though I got the impression that the
Gecko ActiveX support would be for custom ActiveX controls and not
Microsoft ones such a Word.Application.
Richard.