So i am generating form on fly and posting it to another website. The problem is that when i'am using IE form post request contains no parameters. The form outerHTML is the same in Mozilla and IE 8, so i just can not understand it does not work properly in IE 8. Is there any way to fix ?
Here is the logic that posts generates & posts the form:
function PostForm() {
var form = AddForm();
var email = hiddenEmailCtrl.value;
var password = hiddenPasswordCtrl.value;
var checked = rememberMeCtrl.checked;
AddField(form, "email", email);
AddField(form, "password", password);
AddField(form, "remember_me", checked);
form.action = 'https://somesite.com/login';
alert(form.outerHTML);
alert(document.forms[1].outerHTML);
document.forms[1].submit();
}
function AddForm() {
var submitForm = document.createElement("form");
document.body.appendChild(submitForm);
submitForm.id = 'credentialsForm';
submitForm.method = "post";
submitForm.target = '_blank';
return submitForm;
}
function AddField(formElement, fieldName, fieldValue) {
开发者_StackOverflow中文版var inputElement = null;
if (typeof (document.all) != undefined && document.all) {
inputElement = document.createElement("<input type='hidden' name='" + fieldName + "' value='" + fieldValue + "' />");
inputElement.id = fieldName;
}
else {
inputElement = document.createElement('input');
inputElement.setAttribute('type', 'hidden');
inputElement.setAttribute('name', fieldName);
inputElement.setAttribute('value', fieldValue);
inputElement.id = fieldName;
}
if (inputElement == null) return null;
formElement.appendChild(inputElement);
return inputElement;
}
And here is Mozilla request :
POST /login HTTP/1.1
Content-Type: application/x-www-form-urlencoded
Host: ensiconnect.groupsite.com
Content-Length: 42
Expect: 100-continue
Connection: Keep-Alive
email=some@email.com&password=somePassword
This is IE8 request:
CONNECT somesite.com:443 HTTP/1.0
User-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; InfoPath.1; .NET4.0C; .NET4.0E; AskTbF-ET/5.9.1.14019)
Proxy-Connection: Keep-Alive
Content-Length: 0
Host: ensiconnect.groupsite.com
Pragma: no-cache
IE uses a nonstandard version of document.createElement
that also supports HTML code instead of a simple tag name. Since this violates the standard, and IE8 went to some length to be more compliant, it's possible IE8 only obeys the non-standard variant in quirks mode.
You should try removing the switch on document.all
and pass IE8 the w3c variant in AddField
. If that works then you'll need to test for IE7 rather than document.all
btw, I'm just guessing here, you'll need to test it.
精彩评论