RSS Feed

September, 2011

  1. Javascript created form submission to iframe opens new tab IE

    September 12, 2011 by Dave

    Well; of course, Internet Explorer invents its own rules and anyone trying to create a form with JavaScript and submit it to an iframe also created with JavaScript will know that this causes Internet Explorer to submit it to a new tab..

    Very annoying, But here is a solution.

    When you’re creating your iframe, don’t create it as a DOM element, create a wrapper for it and change its innerHTML.

    See below

    var a = document.createElement('div');
    document.appendChild(a);
    a.innerHTML = '<iframe name="targetMe" id="targetMe"></iframe>'
    

    Now your form can target that iFrame! Easy!


  2. C Fakepath fix

    September 1, 2011 by Dave

    So I’m sure any developers reading this have come across the Safari, IE7+ and Opera issue where an upload field is for whatever reason filled with C:\fakepath\filename GRR! How annoying!

    But below is a really simple fix!

        //get our form field
        var a = document.getElementById('myUploadField'),
            b = encodeURI(a.value),
            c = b.replace("C:%5Cfakepath%5C","");
        //We then listen for the value changing and
        //remove the C:\fakepath\ from it! easy!
        a.onchange = function () {
            this.value = c;
        }
    

    How easy was that!