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.

When I check "view source > frame info" on the window produced by the jQuery code below, it cuts off the querystring at the &type=image. I'm url encoding the ampersands properly, right?

Address: ...wp-admin/media-upload.php?post_id=28&type=image&

function wpe_customImages($initcontext)
{
global $post;
?>
<script type="text/javascript">
jQuery(document).ready(function() {
var fileInput = '';
jQuery('#wpe-uploadAttachments').click(function() {
    fileInput = jQuery(this).prev('input');
    formfield = jQuery('#upload_image').attr('name');
    post_id = jQuery('#post_ID').val();
    tb_show('', 'media-upload.php?post_id='+post_id+'&amp;type=image&amp;TB_iframe=true&amp;wpe_idCustomAttachment=true');
    return false;
});
share|improve this question
    
Can you provide us with a screenshot? –  EAMann Nov 19 '10 at 19:14
add comment

1 Answer

up vote 3 down vote accepted

As you have asked wether or not you have done the url encoding for the ampersands right, then my answer is: No.

You are calling a javascript function, you're not outputting something as x(ht)ml. You therefore do not need to encode & as &amp;. The function is expecting a URL not a string that contains an xml encoded url.

But that's probably nit-picking.

The reason why this does not work is, that tb_show() cut's away anything after the first TB_ it finds in that URL, and only the part of the URL before that string is preserved for the iframe src. So you need to move the TB_iframe=true to the end of the parameter. This should do the trick:

tb_show('', 'media-upload.php?post_id='+post_id+'&amp;type=image&amp;wpe_idCustomAttachment=true&amp;TB_iframe=true');

BTW, wordpress is open source. You can just look to find the tb_show() function in source and look why something is happening or not. This can help to find out specific stuff. I didn't do anything else :)

share|improve this answer
    
That did it. Thanks for the help. –  Scott B Nov 19 '10 at 20:58
    
That's a very good point, it's not really an immediately obvious problem but i do specifically remember noticing that issue myself (the TB_ parameter positioning). Good call hakre.. :) –  t31os Nov 20 '10 at 11:16
add comment

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.