determine if function exists in IE

Y

yofnik

How do you check if a function exists in IE? If I try the following:

if(document.selectSingleNode)
{
document.selectSingleNode(xpath);
}

I get an error saying the wrong number of arguements were supplied
(obviously the function exists). I have also tried

if(typeof document.selectSingleNode == "function")

but to no avail. Any advice?

Thanks.
 
M

Martin Honnen

if(typeof document.selectSingleNode == "function")

if (typeof document.selectSingleNode != 'undefined') {
// use method here e.g.
document.selectSingleNode('root/child1/child2')
}

The typeof result of that expression if document is an MSXML DOM
document is 'unknown'.
typeof document.getElementById
with IE and document being an IE HTML DOM document gives 'object' so any
comparisons alike
typeof hostObject.methodName == 'function'
might fail while doing
typeof hostObject.methodName != 'function'
should usually suffice (as long as you don't run into situations where
your code is run against two different DOM implementations where one has
a non function property named 'methodName' and the other has a function
property of that name).
 

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,755
Messages
2,569,537
Members
45,022
Latest member
MaybelleMa

Latest Threads

Top