1
 $('#iframe').ready(function() {
   $('#iframe a').attr('target', '_parent');
 });

simple as that.

EDIT:

my html:

 <div id='outerdiv'>
   <iframe src="http://localhost:8888/harvest/blog" id='iframe' scrolling=no></iframe>
 </div>

3 Answers3

3

Have you tried using a .load() event instead? See the below question.

Javascript callback when IFRAME is finished loading?

Community
  • 1
  • 1
Munzilla
  • 3,725
  • 5
  • 27
  • 35
2

To access iframes you need to use 'contents':

  $('#iframe').ready(function() {
       $('#iframe').contents().find('a').attr('target', '_parent');
  });
Jeff B
  • 29,593
  • 6
  • 62
  • 88
  • 1
    Unfortunately, 'ready' doesn't work with iframes, so the content is probably not available when you call this. You need to wait, or provide a callback in your iframe. Or, use load as stated in another answer. But, contents should work if the frame is loaded and on the same domain. – Jeff B Apr 07 '11 at 15:28
  • You're right! awesome. it worked with a timeout on a function. – Daniel says Reinstate Monica Apr 07 '11 at 15:30
1

Maybe because you could not modify the cross-domain iframe document in JavaScript.

Kara
  • 5,996
  • 16
  • 49
  • 56
KARASZI István
  • 29,989
  • 8
  • 97
  • 120