Hi to all, i've a little problem with this script, i can't make it
works in ie.
The problem is that it always opens a new windows when i submit the
upload form, even if i use the target property to a just created
iframe.

In FF, it will target the iframe as expected.

Can you help me?

Here's the code:

function createIFrame() {
    $("<iframe></iframe>")
    .attr("id", "uploadFrame")
    .attr("name", "uploadFrame")
//    .attr("src", "javascript:false") not working
    .css("position", "absolute")
    .css("visibility", "hidden")
    .appendTo("body");
}

function iFrameCallBack(e) {
        if ( e ) {
           $("#uploadFrame").load(e);
        }
}

function removeIFrame() {
        $("#uploadFrame").remove();
}

function insertNewUpload() {
    uploadCounter += 1;
    // Creating the form for the new file upload
    $("<form></form>")
        .appendTo("#allegati")
        .attr("action", "upload")
        .attr("method", "POST")
        .attr("id", "uploadform" + uploadCounter)
        .attr("enctype", "multipart/form-data")
        .attr("target", "uploadFrame");

    // Creating the input for the file
    $("<input type='file'></input>")
        .appendTo("#uploadform"+uploadCounter)
        .attr("name", "file" + uploadCounter)
        .attr("size", "50")
        .change(function(e) { fileUpload($(this)) });
}

function removeUpload($elm) {
    createIFrame();
    $elm.parent().submit();
    iFrameCallBack(confirmDelete($elm));
    removeIFrame();
}

function fileUpload($elm) {
        createIFrame();
        $elm.parent().submit();
        iFrameCallBack(confirmUpload($elm));
        removeIFrame();
        insertNewUpload();
        return false;
}

function confirmDelete($elm) {
        $elm.parent().remove();
}

function confirmUpload($elm) {
    $elm.parent().css("backgroundColor", "#DFFFDF");

    // Creating the remove file button
    $("<input type='button'></input>")
        .appendTo($elm.parent())
        .attr("value", "rimuovi")
        .addClass("std_btn")
        .css("width", "6em")
        .css("font-size", "1em")
        .click(function(e) { removeUpload($(this)); });

    var s = "<span> "+$elm.val()+"</span>";
    var h = "<input type=\"hidden\" class=\"delete\" name=\"delete\"
value=\""+$elm.val()+"\"/>";
    $(s).appendTo($elm.parent());
    $(h).appendTo($elm.parent());

    $elm.remove();
}

Reply via email to