Jquery window.send_to_editor

后端 未结 9 1196
慢半拍i
慢半拍i 2020-12-24 09:22

Couldn\'t come up with a good title for this.

I\'ve got a build in WordPress where I have multiple image uploads using the built in WordPress media uploader. How it\

9条回答
  •  醉酒成梦
    2020-12-24 10:09

    Here is my rendition:

    It also allows you to insert PDF's files or anything without a SRC attribute by doing a check for img src and if none, trying href on the document. This one also allows you to use classes and apply this to multiple items.

    The Javascript:

        var formfield = "";
        jQuery('.browse_upload').click(function() {
                formfield = jQuery(this).attr('name');
                tb_show('', 'media-upload.php?type=image&TB_iframe=true');
    
                return false;
        });
        window.send_to_editor = function(html) {
                hrefurl = jQuery('img',html).attr('src');
                if(jQuery(hrefurl).length == 0) {
                    hrefurl = jQuery(html).attr('href'); // We do this to get Links like PDF's
                }
                jQuery('.' + formfield).val(hrefurl);
                tb_remove();
    
        }
    

    Sample HTML

    
    
    

提交回复
热议问题