0x80004005 (NS_ERROR_FAILURE) [nsIDOMHTMLFormElement.submit]

I created a method to extract some data (lat, lon points) and open a window for matching 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(); } 

The data variable is populated as follows:

map coorindates

However, I get the following line on the line:

 mapInput.value = data; 

ERROR: uncaught exception: [Exception ... "Component returned DTC: 0x80004005 (NS_ERROR_FAILURE) [NsIDOMHTMLFormElement.submit]" nsresult: "0x80004005 (NS_ERROR_FAILURE)" location: "JS frame :: http ://www.xx :: openMapWindow :: line 244 "data: no]

Line 0

+3
source share
1 answer

This is due to the browser popup blocker. If you look closely at the error, it describes submit "button" as a problem, not the mapValue.input line.

The following code works for me:

http://jsfiddle.net/WDFNL/

 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'); 

At first I got the error you are describing, but this is due to my popup blocker. As soon as I allowed jsfiddle.net to allow pop-ups, it started working.

EDIT

There is an easy way to check this and alert the user if his pop-up blocker disables the card:

http://jsfiddle.net/WDFNL/1/

 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'); 

Pay attention to the map variable. You can check it to see if window.open returned a window handle and acts accordingly depending on the result.

+6
source

All Articles