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

Q1026 How can I display one image if the browser supports image swapping and other if it doesn't?

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

Q1026 How can I display one image if the browser supports image swapping and other if it doesn't?

One way:

<SCRIPT LANGUAGE="JavaScript"><!--
if (document.images)
    document.write('<IMG SRC="javascriptenabled.gif" WIDTH="100" HEIGHT="100">');
else
    document.write('<IMG SRC="javascriptdisabled.gif" WIDTH="100" HEIGHT="100">');
//--></SCRIPT>

<NOSCRIPT>
<IMG SRC="javascriptdisabled.gif" WIDTH="100" HEIGHT="100">
</NOSCRIPT>

Alternatively:

<IMG NAME="myImage" SRC="javascriptdisabled.gif" WIDTH="100" HEIGHT="100">

<SCRIPT LANGUAGE="JavaScript"><!--
if (document.images)
    document.images.myImage.src = 'javascriptenabled.gif';
//--></SCRIPT>

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.