Check for showModalDialog support

J

johkar

Just want a verification of logic. This seems to work for IE and
Firefox, but I wonder if it would be a problematic test in any of the
other latest browsers? Is the use of the "window" object correct? I
didn't think it would be document.showModalDialog.

if(window.showModalDialog){
//do something
}
else
{
//do something else
}

Thanks, John
 
R

Randy Webb

johkar said the following on 2/8/2006 8:47 AM:
Just want a verification of logic. This seems to work for IE and
Firefox, but I wonder if it would be a problematic test in any of the
other latest browsers? Is the use of the "window" object correct?

What does the documentation say?
I didn't think it would be document.showModalDialog.

It won't.
 
T

Thomas 'PointedEars' Lahn

johkar said:
Just want a verification of logic. This seems to work for IE and
Firefox, but I wonder if it would be a problematic test in any of the
other latest browsers?

You only test for the existence and true-value of the property, not if it is
a method. That /is/ problematic, for another DOM could pose as IE DOM and
a call on this property could result in a TypeError.
Is the use of the "window" object correct?

It is, RTFM. showModalDialog is a method of Window objects in the IE DOM.

I didn't think it would be document.showModalDialog.

It is not.
if(window.showModalDialog){
//do something
}
else
{
//do something else
}

function isMethodType(s)
{
return (s == "function" || s == "object");
}

if (typeof window != "undefined"
&& isMethodType(typeof window.showModalDialog))
{
// do something _with showModalDialog_
}
else
{
// do something else
}


PointedEars
 

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,536
Members
45,012
Latest member
RoxanneDzm

Latest Threads

Top