Trang web này sẽ có chức năng hạn chế trong khi chúng tôi trải qua bảo trì để cải thiện trải nghiệm của bạn. Nếu một bài viết không giải quyết được vấn đề của bạn và bạn muốn đặt câu hỏi, chúng tôi có cộng đồng hỗ trợ của chúng tôi đang chờ để giúp bạn tại @FirefoxSupport trên Twitter và /r/firefox trên Reddit.

Tìm kiếm hỗ trợ

Tránh các lừa đảo về hỗ trợ. Chúng tôi sẽ không bao giờ yêu cầu bạn gọi hoặc nhắn tin đến số điện thoại hoặc chia sẻ thông tin cá nhân. Vui lòng báo cáo hoạt động đáng ngờ bằng cách sử dụng tùy chọn "Báo cáo lạm dụng".

Tìm hiểu thêm

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.
Đính kèm ảnh chụp màn hình

Được chỉnh sửa bởi bobjtls vào

Giải pháp được chọn

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.

Đọc câu trả lời này trong ngữ cảnh 👍 1

Tất cả các câu trả lời (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

Được chỉnh sửa bởi bobjtls vào

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.

Được chỉnh sửa bởi bobjtls vào

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

Giải pháp được chọn

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?