Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.6k views
in Technique[技术] by (71.8m points)

javascript - 0x80004005 (NS_ERROR_FAILURE) [nsIDOMHTMLFormElement.submit]

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:

map coorindates

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.

The below code is working 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');

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.

EDIT

There is an easy way to test for this and alert the user if their popup blocker is disabling the map:

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

Note the map variable. You can test it to see if window.open returned a window handle, and act accordingly depending on the result.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...