jQuery iframe access working only the first time in Firefox
I am using jQuery and Ruby On Rails.
I have an ajax call $.get()
which renders a piece of html containing a iframe
I want to modify the iframe in order to make sure the <a>
links open in a new window.
To do this I have added an onload to the iframe definition:
<iframe id="iframe_message_<%= message.id %>" class="iframe_message" name ="iframe_message_<%= message.id %>" width="100%" frameborder="0" src="<%= message.attachments.body_html.first.document.url %>" onLoad="autoResize('iframe_message_<%= message.id %>');">
the autoResize
function is defined in the html rendered by the ajax call and contains:
$(".iframe_message").ready(function () {
$('a', frames[id].document).attr('target','_blank');
});
This works fine in IE, Safari but I have a problem with firefox where it works the first time the $.get()
is called by a mouse click but not on the following click (the <a>
tags are not modified).
I thought on a caching issue and replaced the 开发者_如何学C$.get()
by the $.ajax()
with cache:true
but I still have the same behaviour.
Any ideas on what could be the problem?
Hard to tell from your description, but your jquery may need to be called from within the iframe. Think of the iframe as a separate web page.
I went of the jQuery website and looked at the .content description and my "working" code is
$("#"+id).contents().find("a").attr('target','_blank');
where "#"+id
is the id of my iframe.
精彩评论