Firefox window.onerror problem - warning "Script error!" only

I am using window.onerror to alert JavaScript errors for debugging.

window.onerror = function(msg, url, line) {
    alert(msg + '\nLine: ' + line);
};

      

On launching the error, it may alert you to the actual error message in IE. But in firefox it just warns "Script error!" But I still see the actual error message in the firefox error console.

I remembered a few months ago when I was working on another project firefox didn't work like that. But I cannot get the code for this project at the moment. So I am wondering what are the possible problems with this?

+2


a source to share


3 answers


Now I know the answer. After I uploaded the file to the webserver (actually localhost), it visited it via http: //localhost/path/to/the/file.html , the window.onerror event works as expected (as in IE, warning the actual error message instead of "Script error"). But it doesn't work when visiting the file locally via file: /// D: /path/to/the/file.html



Can't figure out why?

0


a source


window.onerror(function(msg, url, line) {

      

Do you mean:



window.onerror= function(msg, url, line) {

      

+1


a source


You need to make sure that the domain you are running the script on is the same as the domain of your page. You should be able to get the correct filename and line number if both are the same.

Tested on IE8, FF 3.6 and Chrome 10 beta seconds ago.

0


a source







All Articles