Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have a link in a metabox that brings up a Thickbox iFrame of another page on my site. It works fine, except that I can't seem to affect the DOM of the page in the iFrame.

What do I have to do to this to get it to work? The code below works when I run it in the console after loading the Thickbox, but it doesn't work when I simply include it in the metabox code.

jQuery('#TB_iframeContent').contents().find( 'html' ).css('border', '5px solid red');

Wrapping it a .load() function (so as to wait for the iFrame to fully load) didn't work either:

jQuery('#TB_iframeContent').load(function() {
    alert('iframe is loaded');
    jQuery('#TB_iframeContent').contents().find( 'html' ).css('border', '5px solid red');
});

The alert is never fired either.

What am I missing?

(Ps. I am not just trying to add a red border; that's just for the sake of illustration :) Also: I'm posting this here instead of SO because I have read that WP's built-in Thickbox code is somewhat customized.)

share|improve this question

1 Answer 1

jQuery(document).ready(function($) {   
   $('.yourlink').click(function() { 

    tbframe_interval = setInterval(function() {
          $('#TB_iframeContent').contents().find('.savesend input[type="submit"]').val('changed the button text');
    }, 2000);
    tb_show('', 'media-upload.php?type=image&TB_iframe=true');
    return false;
   });
});

http://www.webmaster-source.com/2010/01/08/using-the-wordpress-uploader-in-your-plugin-or-theme/

you can also enqueue a script on the media upload page that should be available in you iframe, don't know if that will do it though. am working on something very similar to what you are doing atm.

add_action( 'admin_print_scripts-media-upload-popup',  'kia_enqueue_script' );

function kia_enqueue_script(){
    wp_enqueue_script('prism-thumbnails','link to your script');
}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.