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!

搜索 | 用户支持

防范以用户支持为名的诈骗。我们绝对不会要求您拨打电话或发送短信,及提供任何个人信息。请使用“举报滥用”选项报告涉及违规的行为。

详细了解

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.
已附加屏幕截图

由bobjtls于修改

被采纳的解决方案

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.

定位到答案原位置 👍 1

所有回复 (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

由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.

由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

选择的解决方案

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?