2014-09-14 3 views
0

Почему это не работает в Firefox, но работает в Chrome?Форма submit() не работает в firefox, но работает в chrome?

<script> 
var newValue = 'test'; 

var f = document.createElement('form'); 
f.setAttribute('method','GET'); 
f.setAttribute('action','/test'); 

var customContext = document.createElement('input'); 
customContext.setAttribute('type','text'); 
customContext.setAttribute('name','CUSTOM_CONTEXT'); 
customContext.value = newValue; 

var s = document.createElement('input'); //input element, Submit button 
s.setAttribute('type','submit'); 
s.setAttribute('value','Submit'); 

f.appendChild(customContext); 
f.appendChild(s); 

f.submit(); 
</script> 
+0

какие-либо ошибки бросили? 'newValue' не определен в показанном коде – charlietfl

+0

' newValue' был передан через функцию, на данный момент я жестко закодировал значение. В консоли нет ошибок. – bobbyrne01

+0

работает для меня в FF – charlietfl

ответ

0

Как отметил @Boaz ..

It could be related to the fact that the form is not actually in the DOM. 
Try appending the form to the body and see the difference. 
You can also set the field to be type="hidden" so the addition should not be visible 
Смежные вопросы