Javascript 0x80004005 (NS_ERROR_FAILURE) [nsIDOMHTMLFormElement.submit]
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5686377/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
0x80004005 (NS_ERROR_FAILURE) [nsIDOMHTMLFormElement.submit]
提问by php-b-grader
I have created a method to retrieve some data (lat,lon points) and open a window to map them.
我创建了一种方法来检索一些数据(纬度、经度)并打开一个窗口来映射它们。
function openMapWindow (data) {
alert(data);
var mapForm = document.createElement("form");
mapForm.target = "Map";
mapForm.method = "POST"; // or "post" if appropriate
mapForm.action = "/map.php";
var mapInput = document.createElement("input");
mapInput.type = "text";
mapInput.name = "addrs";
mapInput.value = data;
mapForm.appendChild(mapInput);
document.body.appendChild(mapForm);
window.open("", "Map", "status=0,title=0,height=600,width=800");
mapForm.submit();
}
data variable is populated with the following:
数据变量填充了以下内容:
Yet I get the following area on the line:
然而,我在线上得到以下区域:
mapInput.value = data;
ERROR: uncaught exception: [Exception... "Component returned failure code: 0x80004005 (NS_ERROR_FAILURE) [nsIDOMHTMLFormElement.submit]" nsresult: "0x80004005 (NS_ERROR_FAILURE)" location: "JS frame :: http://www.xxx.xxx:: openMapWindow :: line 244" data: no]
Line 0
错误:未捕获的异常:[异常......“组件返回失败代码:0x80004005(NS_ERROR_FAILURE)[nsIDOMHTMLFormElement.submit]” nsresult:“0x80004005(NS_ERROR_FAILURE)”位置:“JS框架::http://www.xxx.xxx :: openMapWindow :: line 244" 数据:无]
第 0 行
回答by Jared Farrish
It has to do with your browser's popup blocker. If you look closely at the error, it's describing the submit "button" as the problem, not the mapValue.input line.
它与浏览器的弹出窗口拦截器有关。如果您仔细查看错误,它会将提交“按钮”描述为问题,而不是 mapValue.input 行。
The below code is working for me:
以下代码对我有用:
function openMapWindow (data) {
alert(data);
var mapForm = document.createElement("form");
mapForm.target = "Map";
mapForm.method = "POST"; // or "post" if appropriate
mapForm.action = "/map.php";
var mapInput = document.createElement("input");
mapInput.type = "text";
mapInput.name = "addrs";
mapInput.value = data;
mapForm.appendChild(mapInput);
document.body.appendChild(mapForm);
window.open("", "Map", "status=0,title=0,height=600,width=800");
mapForm.submit();
}
openMapWindow('-35.308401,149.124298-35.307841,149.124298');
I did get the error you're describing at first, but it had to do with my popup blocker. Once I authorized jsfiddle.net to be allowed popups, it started working.
一开始我确实遇到了您描述的错误,但这与我的弹出窗口阻止程序有关。一旦我授权 jsfiddle.net 允许弹出窗口,它就开始工作了。
EDIT
编辑
There is an easy way to test for this and alert the user if their popup blocker is disabling the map:
有一种简单的方法可以对此进行测试,并在弹出窗口阻止程序禁用地图时提醒用户:
function openMapWindow (data) {
var mapForm = document.createElement("form");
mapForm.target = "Map";
mapForm.method = "POST"; // or "post" if appropriate
mapForm.action = "/map.php";
var mapInput = document.createElement("input");
mapInput.type = "text";
mapInput.name = "addrs";
mapInput.value = data;
mapForm.appendChild(mapInput);
document.body.appendChild(mapForm);
map = window.open("", "Map", "status=0,title=0,height=600,width=800");
if (map) {
mapForm.submit();
} else {
alert('You must allow popups for this map to work.');
}
}
openMapWindow('-35.308401,149.124298-35.307841,149.124298');
Note the map
variable. You can test it to see if window.open
returned a window handle, and act accordingly depending on the result.
注意map
变量。您可以测试它以查看是否window.open
返回了一个窗口句柄,并根据结果采取相应的行动。