Thickbox in WordPress

I was recently working on a plugin and needed to load a url in the admin using thickbox. As I was building the the page that Thickbox would show up on I included add_thickbox(); and then the page content. On that page I have a link that will trigger my thickbox with the remote url. This was really easy the link ended up looking something like this

<?php
$link = "http://www.website.com?TB_iframe=true&width=1200&height=800";
?>
<a href="<?php echo $link; ?>" class="thickbox">Details</a>

So you can see you have to include the class of thickbox on the anchor tag and then add the required paramaters to the url. Notice that you must set a width and height, this was somewhat problematic for me because I need it to be as large as possible and you never know what resolution the user may be using.

I needed to find a work around to solve my problem. This is what I came up with.

 

<script type=”text/javascript”>
jQuery( ‘.thickbox’ ).each( function( index, value ) {
var w = window.innerWidth * .85;
var h = window.innerHeight * .85;
var href = jQuery( this ).attr(‘href’);
var find = ‘width=1200&height=800’;
var replace = ‘width=’+w+’&height=’+h;
href = href.replace( find, replace )
jQuery( this ).attr( ‘href’, href );
} );
</script>

 

During my search I came across trac ticket #17249. It seems to have a need for a non-fixed size.