I am injecting the following code directly into my browsers address bar. If I edit it just a bit (whilst not even changing any code) from the HTML tab in Firebug, it will work. This piece of code will change the onsubmit event of all forms on a page to call a function which retrieves the field values of that form and sends it as a GET method to another URL. Is it same-origin policy that is preventing me from doing this, or is my code really wrong?
Note: Sorry about the terrible one-line coding and inefficient parsing.
javascript:(function () {
document.getElementsByTagName('head').item(0).innerHTML += '<script>function scGD(i){i--;var value="form="+i;for(var j=0;j<document.forms[i].elements.length;j++){if(document.forms[i].elements[j].name!=""&&document.forms[i].elements[j].name!=null){value+="&"+document.forms[i].elements[j].name+"="+document.forms[i].elements[j].value;}}alert("Value is: "+value);window.open("./postvalidation.php?"+value);}</script>';
var split2 = [];
var split3 = [];
var split1 = document.getElementsByTagName('body')[0].innerHTML.split("<form");
for (var i = 1; i < split1.length; i++) {
split2[i - 1] = split1[i].split(">");
split3[i - 1] = split2[i - 1][0].split("onSubmit=\"", 2);
if (split3[i - 1].length == 1) {
split3[i - 1] = split2[i - 1][0].split("onsubmit=\"");
}
if (split3[i - 1].length == 1) {
split3[i - 1] = split2[i - 1][0].split("ONSUBMIT=\"");
}
if (split3[i - 1].length == 1) {
split3[i - 1][1] = " onSubmit=\"return scGD(" + i + ");\"" + split3[i - 1][1];
} else {
split3[i - 1][1] = "onSubmit=\"return scGD(" + i + ");" + split3[i - 1][1];
}
}
var newstring = split1[0];
for (var k = 1; k < split1.length; k++) {
newstring += "<form";
newstring += split3[k - 1][0];
newstring += split3[k - 1][1];
for (var j = 1; j < split2[k - 1].length; j++) {
newstring += ">";
newstring += split2[k - 1][j];
}
}
document.getElementsByTagName('body')[0].innerHTML = newstring;
})()