472,121 Members | 1,560 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,121 software developers and data experts.

Images don't load when using JavaScript in SRC= attribute for FireFox


I'm in a quandary as to how to address a problem. The site in question:


On the left-hand side of the site are image navigation elements that
change when clicked based on where you are in the navigation heirarchy.
They work just fine in IE, but Firefox doesn't load the initial state
of the images. If you mouse over the images that have onmouseover or
onmouseout events, though, the images associated with those events do
pop up correctly. I have tired a few "best guess" stabs using OnLoad
events to no avail. Grateful for your help. Javascript file is at.


sample HTML code:

<a href="../" onMouseOver="imgHov('home');"

<img src="javascript:simNav('home');" name="home" border="0" width="66"

The simNav function:

function simNav(n_name) {
var url =this.location.href
root_name =url.substring(url.indexOf(n_name),eval(url.indexO f(n_name)+
if (this.document) {
if (n_name == root_name || (n_name == "home" && homepage ==
"y")) {
document[n_name].src = eval(n_name + "On" + ".src");
} else {
document[n_name].src = eval(n_name + "Off" + ".src");
return (document[n_name].src);

Sample image source loading for javascript:

homeOn = new Image(); // Active images
homeOn.src = "/images/n_home_on.gif";

Very grateful for your help!

Jan 21 '06 #1
3 1989

I don't think using javascript: call as protocol hanndler on an
attribute has been added as standard, so, it seems proprietary so
far, last I looked in HTML4.01 specs, they have reserved for future
works to add it BUT using ="{&yourcodehere}" NOT javascript:, but has
not been added yet on xhtml1 or else yet, thus.

Jan 22 '06 #2

jb******@gmail.com wrote:
<img src="javascript:simNav('home');"

You have no clue what a javascript: URL is good for, the expression
following the javascript: is supposed to yield the data to load so
unless your simNav('home') call returns image data that the image
element can render that construct is pointless.

See <http://www.elf.org/pnglets/> where that is used in a way it makes

If you need to call that simNav function then use
<script type="text/javascript">
where that function needs to be called.
Use a static image element e.g.
<img src="whatever.gif" alt="whatever" name="whatever">
so that with or without JavaScript the image or its alt text is rendered.
If you only want to render the img element with script then use
<script type="text/javascript">
'<img src="whatever.gif" alt="whatever" name="whatever">');
of course there you have all the power of JavaScript expressions thus if
you have a function yielding a URL then you can do
<script type="text/javascript">
'<img src="' + getURL('whatever') + '" alt="whatever" '>');


Martin Honnen
Jan 22 '06 #3
Interesting solution, worth trying, many thanks. Another alternative I
was thinking of was trying to use an "eval" statement around the
"javascript:" statement, since it seems to execute fine enough once the
page is loaded.

John Blossom

Jan 23 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

11 posts views Thread by Penelope Baker | last post: by
3 posts views Thread by src_mag | last post: by
2 posts views Thread by Trent | last post: by
10 posts views Thread by cosmic foo | last post: by
61 posts views Thread by phil-news-nospam | last post: by
3 posts views Thread by littleark | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.