I use this code on my wordpress plugin to return the src of the image the user selected in the wordpress media uploader.
The problem that this code does not return the image src if only the image returned by the uploader screen.
The Jquery code:
window.send_to_editor = function(html) {
alert(html);
imgurlv = jQuery(html).find('img').attr('src');
alert(imgurlv);
jQuery(targetfield3).val(imgurlv);
tb_remove();
}
example:
Code returned by uploader is:
<a class="shutterset_" href='http://localhost/1/wp-content/gallery/bm/01.jpg' title=''><img src='http://localhost/1/wp-content/gallery/bm/thumbs/thumbs_01.jpg' alt='01' class='ngg-singlepic ngg-none' /></a>
The img src is returned like this: http://localhost/1/wp-content/gallery/bm/thumbs/thumbs_01.jpg
But if the code returned by uploader is this:
<img src='http://localhost/1/wp-content/gallery/bm/thumbs/thumbs_01.jpg' alt='01' class='ngg-singlepic ngg-none' />
The jquery code returns undefined.
what is wrong?
You could hack it with:
Problem is, ‘find’ looks at children of the current element. In the second case, the
imgelement is the top level, so none of it’s children have asrcproperty to find.