javascript function not found in Firefox but working perfectly in Safari and Chrome on a Mac
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)
Hi, your source view does not match the page Firefox actually loads (note the redirected address):
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 เมื่อ
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 เมื่อ
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.
วิธีแก้ปัญหาที่เลือก
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.
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
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?