Home Articles FAQs XREF Games Software Instant Books About Feedback Search Site-Map
irt.org logo

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

irt.org | Knowledge Base | JavaScript | Image | Q562 [ previous next ]

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

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?'


Provide feedback ...
AddThis Social Bookmark Button

Provide feedback ... AddThis Social Bookmark Button


Last Updated: 30th March 2008. Maintained by: Martin Webb and Michel Plungjan
irt.org liability, trademark, document use, privacy statement and software licensing rules apply.
Copyright © 1996-2008 irt.org, All Rights Reserved.