我正在使用以下内容来发布信息,当我创建表单元素时,我得到一个例外:“权限被拒绝”。
var newWindow = window.open('', '_blank', 'alwaysRaised=yes,toolbars=no, menubar=no, location=no, scrollbars=yes, resizable=yes, status=yes,left=10000, top=10000, width=10, height=10, visible=none', '');
var tempFormElement = newWindow.document.createElement('form');
tempFormElement.method = 'post';
tempFormElement.action = urlToOpen;
var tempInputElement;
tempInputElement = newWindow.document.createElement('input');
tempInputElement.setAttribute('TPLInfo', JSON.stringify(linkageInfo));
tempFormElement.appendChild(tempInputElement);
tempFormElement.submit();
newWindow.document.body.removeChild(tempFormElement);
newWindow.close();
请建议。
答案 0 :(得分:1)
所以我建议 - 如果可以的话:
使用jQuery的Ajax
$.post(urlToOpen,{"TPLInfo":JSON.stringify(linkageInfo)});
或者如果不在同一个域上(普通JS):
var newWindow;
var urlToOpen = "....";
function perform() {
if (!newWindow) {
alert("Sorry, you must allow popups");
return;
}
var tempFormElement = newWindow.document.createElement('form');
tempFormElement.method = 'post';
tempFormElement.action = urlToOpen;
var tempInputElement;
tempInputElement = newWindow.document.createElement('input');
tempInputElement.setAttribute("name","TPLInfo");
tempInputElement.value = JSON.stringify({"a":"1"});
tempFormElement.appendChild(tempInputElement);
newWindow.document.body.appendChild(tempFormElement);
tempFormElement.submit();
}
window.onload=function() {
document.getElementById("but").onclick=function() {
// var parms = "alwaysRaised=yes,toolbars=no,menubar=no,location=no,scrollbars=yes,resizable=yes,status=yes,left=10000,top=10000,width=10,height=10,visible=none";
// valid parms, yes I know you want to hide and close but nope.
var parms = "scrollbars,resizable,status,left=10000,top=10000,width=100,height=100";
newWindow = window.open('', '_blank',parms);
setTimeout(perform,500); // give IE time to get over opening
}
}