Join the AMA (Ask Me Anything) with the Firefox leadership team to celebrate Firefox 20th anniversary and discuss Firefox’s future on Mozilla Connect. Mark your calendar on Thursday, November 14, 18:00 - 20:00 UTC!

This site will have limited functionality while we undergo maintenance to improve your experience. If an article doesn't solve your issue and you want to ask a question, we have our support community waiting to help you at @FirefoxSupport on Twitter and/r/firefox on Reddit.

Search Support

Avoid support scams. We will never ask you to call or text a phone number or share personal information. Please report suspicious activity using the “Report Abuse” option.

Learn More

javascript function not found in Firefox but working perfectly in Safari and Chrome on a Mac

more options

I have a web page that uses javascript to display a different page when the user clicks on an image. This works perfectly in Safari and Chrome but not in Firefox. The debugger reports that the javascript function getCaption is not found.

You can see this (not) working at http://yvonneboag.com. Click on Browse images and then select one of the media types to see the page of available images. Clicking on a thumbnail should show a new page (imagedetail.html) with a single larger image and the caption.

The code for the drawings images is attached. The other image is the starting page, showing the thumbnails and captions.

I have a web page that uses javascript to display a different page when the user clicks on an image. This works perfectly in Safari and Chrome but not in Firefox. The debugger reports that the javascript function getCaption is not found. You can see this (not) working at http://yvonneboag.com. Click on Browse images and then select one of the media types to see the page of available images. Clicking on a thumbnail should show a new page (imagedetail.html) with a single larger image and the caption. The code for the drawings images is attached. The other image is the starting page, showing the thumbnails and captions.
Priloženi snimci ekrana

Izmjenjeno od strane bobjtls

Izabrano rješenje

The code works if I open the iframe in a new tab (This Frame: Open Frame in New Tab), but not when this document is in the iframe.

Could this be a problem with the target attribute?

It works if I remove the target="_top" attribute.

Pročitajte ovaj odgovor sa objašnjenjem 👍 1

All Replies (7)

more options

Hi, your source view does not match the page Firefox actually loads (note the redirected address):

http://www.cultconv.com/yvonneboag/drawing.html

more options

Hi jscher. There are two drawing.html files. The one that loads initially is the outer file which contains an iframe loading the inner drawing.html file. The inner file is actually in a sub folder. The code I provided is for the inner file as that is the one that is causing the problem.

I attach the relevant part of the source code for the outer file.

So, when you click on the Drawings button, you load the outer file which in turn loads the inner file through the iframe.

Sorry, I should have described this in my original post.

It makes me think, though, maybe the compiler is getting confused. I will rename the inner file and see if that makes any difference.

bobj

Izmjenjeno od strane bobjtls

more options

Just changed the inner filename to drawingdata.html. Made no difference.

When the inner page loads and you move the mouse onto one of the thumbnails, Firefox displays the javascript call in the small bar at the bottom left of the window (see attached). So, Firefox correctly recognises that the HREF attribute of the anchor is a javascript call.

Izmjenjeno od strane bobjtls

more options

I missed that! It raises a good question: why does it not work in the frame, but if you right-click the framed page > This Frame > Open Frame in New Tab, it works when it's not framed. Hmm...

This seems to be a problem with putting your script in the href. Could you try a global replace in your text editor:

FIND WHAT: href="javascript:

REPLACE WITH: href="javascript:void(0);" onclick="

The onclick handler runs first, and then the link is activated second, but href="javascript:void(0)" deadens the link to prevent any conflicting navigation.

more options

Odabrano rješenje

The code works if I open the iframe in a new tab (This Frame: Open Frame in New Tab), but not when this document is in the iframe.

Could this be a problem with the target attribute?

It works if I remove the target="_top" attribute.

more options

cor-el, you are right, removing the target attribute makes things work perfectly. Thank you for that. Not sure why I didn't think of trying that. In hindsight, that attribute it redundant since the change using the top.window.location.href reloads the entire window anyway.

Thanks again both of you.

bobj

more options

cor-el said

Could this be a problem with the target attribute?

It works if I remove the target="_top" attribute.

Maybe the _top attribute is causing Firefox to look for the script in the top-level (outer) document. Is that a bug?