[英]how do you make form.submit() work in firefox?
我已經實現了以下代碼:
function post(path, params) {
var form = document.createElement('form');
form.setAttribute('target', '_blank');
form.setAttribute('method', 'post');
form.setAttribute('action', path);
var hiddenField = document.createElement('input');
hiddenField.setAttribute('name', 'JSON');
hiddenField.setAttribute('type', 'submit');
hiddenField.setAttribute('value', JSON.stringify(params));
form.appendChild(hiddenField);
form.submit();
}
它在chrome,safari和IE中都可以很好地工作,但是在使用Firefox時卻什么也沒做。
任何想法可能是什么問題?
嘗試添加
document.body.appendChild(form)
提交之前
在Firefox提交表單之前,您需要將表單放入頁面的DOM中。
document.body.appendChild(form);
form.submit();
…應該可以解決問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.