Home Articles FAQs XREF Games Software Instant Books BBS About FOLDOC RFCs Feedback Sitemap
irt.Org
#

Q562 Why do you test for the image object instead of the replace method before using the replace method?

You are here: irt.org | FAQ | JavaScript | Image | Q562 [ previous next ]

Whereas Netscape Navigator allows you to check for the existence or an object with:

if (object.objectname)

or:

if (object.methodname)

without causing a JavaScript error, Internet Explorer allows the check for objects:

if (object.objectname)

but not for methods:

if (object.methodname)

which causes a JavaScript error in Internet Explorer. To get around this inability to perform:

if (location.replace)

in all browsers safely, it is better to check for the existence of something else that indicates whether the replace method is available. It was suggested by Martin Webb in comp.lang.JavaScript that browsers that had the replace method also supported the image object. No one has, yet, proved this to be flawed.

Note: in Opera replace() will work, but only with absolute URL's.

Feedback on 'Q562 Why do you test for the image object instead of the replace method before using the replace method?'

©2018 Martin Webb