Page 1 of 1

Script works locally but not on actual website

Posted: Tue May 01, 2007 6:18 pm
by Ambush Commander
I have a tiny little JavaScript script to swap between GET and POST request modes depending on the size of the request. It looks like this:

Code: Select all

function switch2post(e) {
    var text = document.getElementById('html').value;
    if (text.length < 8000) {
        var form = document.getElementById('filter');
        var action = form.action;
        action = action.substr(0, action.indexOf('?'));
        location.href = action + '?get&html=' + encodeURIComponent(text);
        
        // browser compat code
        if (!e) var e = window.event;
        e.cancelBubble = true;
        if (e.stopPropagation) e.stopPropagation();
        return false;
    }
    return true;
}

function setup_switch2post() {
    var form = document.getElementById('filter');
    form.onsubmit = switch2post;
}

if (window.addEventListener) {
    window.addEventListener("load", setup_switch2post, false);
} else if (window.attachEvent) {
    window.attachEvent("onload", setup_switch2post);
}
...assuming that there is a form named "filter". You can test it here: http://htmlpurifier.org/#Demo

For some reason, it just doesn't work. I'm not getting any JavaScript errors, and local testing indicates that it should work. Have I gone crazy? It appears to work in Internet Explorer. I'm running Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.3) Gecko/20070309 Firefox/2.0.0.3