I'm trying to have an alert popup whenever javascript logs an error. Am I correct in using the code:
window.onerror = function (errorMsg, url, lineNumber) { alert('Error: ' + errorMsg + ' Script: ' + url + ' Line: ' + lineNumber); };
This seems not to produce an alert box. Currently my map is creating a 401 error for a layer every time it loads, as well as an error for a missing favicon, so something should be popping up in the alert box. I've tried putting this code at the start of my javascript file before any other code, inside a function to update layers when they are turned on and off, and inside a function that runs on map load...nothing happens. I'm still learning my way around Javascript so not sure where I'm going wrong.
Solved! Go to Solution.
Laura,
I think because the layer object has an on error event already that it does not bubble to the window object.
I can get this to work for a layer error:
dynamicMapServiceLayer.on("error", function(error){ alert('Error: ' + error.error); });
Laura,
I think because the layer object has an on error event already that it does not bubble to the window object.
I can get this to work for a layer error:
dynamicMapServiceLayer.on("error", function(error){ alert('Error: ' + error.error); });
That works - thank you Robert!