简体   繁体   中英

Why doesn't this jquery code work?

 $('#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>

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

Javascript callback when IFRAME is finished loading?

To access iframes you need to use 'contents':

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

可能是因为您无法在JavaScript中修改跨域iframe文档。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM