Reputation: 10961
I use the window.onerror to alert javascript errors for debugging.
window.onerror = function(msg, url, line) {
alert(msg + '\nLine: ' + line);
};
When an error is fired, it can alert this actual error message in IE. But in firefox, it just alerts "Script error!", but I can still see the actual error message in firefox's error console.
I remembered several months ago when I worked on another project, firefox did not work like this. But I cannot get the code of that project currently. So I wonder what are the possible problems with this?
Upvotes: 2
Views: 1492
Reputation:
You need to ensure that a domain your script is served from is the same as your page domain. You should be able to get a proper filename and line number if both are the same.
Checked on IE8, FF 3.6 and Chrome 10 beta seconds ago.
Upvotes: 0
Reputation: 10961
I know the answer now. After I uploaded the file to a webserver (localhost actually), visited it through http://localhost/path/to/the/file.html, the window.onerror event works as expected (as in IE, alerting the actual error message instead of just "Script error"). But it does not work when visiting the file locally through file:///D:/path/to/the/file.html
Cannot figure out why?
Upvotes: 0
Reputation: 536469
window.onerror(function(msg, url, line) {
You mean:
window.onerror= function(msg, url, line) {
Upvotes: 1