How to upload and insert an image

Code behind

Quite a few people have asked how to upload and insert images into the editor so I've decided to make this little demo with the ImageShack API.

All that's really needed to insert an image is to call wysiwygEditorInsertHtml() or even just insert() on an editor instance. insert() accepts BBCode if using the BBCode plugin, otherwise it accepts HTML.

Setup the editor & upload form

$(function() {
		format: 'bbcode',
        style: '/minified/themes/content/default.min.css',

    // Save this editor instance so the iframe can access it
    window.sceditorInstance = $("textarea").sceditor("instance");


<form action="" method="post" enctype="multipart/form-data" target="upload">
    <p><label>Image: <input type="file" name="media" /></label></p>

    <p><label>Resize Image? <input type="checkbox" name="optimage" id="optimage" value="1" checked onclick="optsize.disabled=!this.checked"></label></p>

    <p><label>Size: <select name="optsize" id="optsize">
        <option value="resample">optimize without resizing</option>
        <option value="100x100">100x75 (avatar)</option>
        <option value="150x150">150x112 (thumbnail)</option>
        <option value="320x320">320x240 (for websites and email)</option>
        <option value="640x640">640x480 (for message boards)</option>
        <option value="800x800">800x600 (15-inch monitor)</option>
        <option value="1024x1024">1024x768 (17-inch monitor)</option>
        <option value="1280x1280">1280x1024 (19-inch monitor)</option>
        <option value="1600x1600">1600x1200 (21-inch monitor)</option>

    <input type="hidden" name="key" value="DEVELOPER_KEY_HERE" />
    <input type="hidden" name="rembar" value="yes" />
    <input type="hidden" name="error_url" value="" />
    <input type="hidden" name="success_url" value="" />

    <p><input type="submit" value="Upload" /></p>
<iframe style="visibility: hidden; height: 0; width: 0" id="upload" name="upload"></iframe>

imageshack-example.html - Page redirected to by the ImageShack API. This will insert the HTML or show the error message.


// Query strnig parser source:
var queryString = {};
    new RegExp("([^?=&]+)(=([^&]*))?", "g"),
    function($0, $1, $2, $3) { queryString[$1] = $3; }

    var img_url = "https://" +
        queryString.server + "" +
        queryString.server + "/" +
        queryString.bucket + "/" + queryString.filename;

    var html = "<a href=\"" + queryString.url + "\">" +
            "<img src=\"" + img_url + "\" alt=\"Uploaded Image\" />" +

    // This called wysiwygEditorInsertHtml on the parent windows
    // SCEditor instance
else if(queryString.message)


When upload form is submitted, it will upload the image to ImageShack via the iframe. Once uploaded ImageShack will then redirect within the iframe to the imageshack-example.html file which will handle inserting the image or showing the error.