I generated a new MetaBox for all standard posts in WordPress 3.1. There I generate a input:text field with the ID _meta_fotos[pic]
, which should hould the image url generated by the standard media-uploader.
I want to use the standard media-uploader from the standard post window. So I generated the following JavaScript code.
jQuery(document).ready(function() {
jQuery('#_meta_fotos\\[pic\\]').focusin(function() {
formfield = jQuery('#_meta_fotos\\[pic\\]').attr('name');
tb_show('', 'media-upload.php?type=image&TB_iframe=true');
return false;
});
window.send_to_editor = function(html) {
imgURL = jQuery('img',html).attr('src');
jQuery('#_meta_fotos\\[pic\\]').val(imgURL);
tb_remove();
}
});
On the first step all works fine. But I don't get the real image URL. All I get back is a URL to the correct uploads-path with a filename blank.gif
.
I checked if the ThickBox is called by the focusin
-function: It is alright.
I think the problem ist in the send_to_editor
-function. It returns in html
the code from the underlaying main-Page and not from the popup-window of the media-uploader/thickbox.
Can anyone help me, to find the mistake? Any help is aprreciated!
alert( html );
.html
if see an empty alert-box. But if I usevar iFrame = jQuery('#TB_iframeContent', html); var iFrameDoc = iFrame[0].contentWindow.document;
and alert theiFrameDoc
i get a html Object.