As I
recently wrote, I am currently developing a mobile version of a single service. Yesterday’s article
about mobile site design features showed that the audience has an interest in developing sites adapted for phones, communicators, etc.
One of the important points on the site is the dynamics for which javascript is responsible. Unfortunately, full support from mobile browsers does not have to wait (for example, jQuery, Prototype, Ext JS, etc. are not intended for browsers in this category, although it should be noted that there are versions of frameworks that are adapted for mobile browsers based on WebKit) . But you can easily do without the support of popular libraries, the main drawback in mobile browsers is the lack of availability of javascript debugging tools (it is possible that Android, iPhone and other advanced devices have similar tools, but I focus on Opera Mini and, unfortunately, IE Mobile ).
The Javascript interpreter in IE Mobile is rather capricious, each time it is very inconvenient to insert alerts into the places of possible errors. A work colleague suggested using the onerror event:
window.onerror = function () {
alert( 'An error has occurred!' );
return true ;
};
Then we tried to add arguments that describe the error: the line number, the page address ... However, IE Mobile did not react to the errors anyway. An Internet search revealed that
there is a way to enable debugging for IE Mobile by adding a parameter to the Windows Mobile registry:
Change the Registry setting “HKEY_CURRENT_USER \ Software \ Microsoft \ Internet Explorer \ Main”. Set dword value of 1
Unfortunately, this method also did not give any results.
On Friday, when I had to figure out for a long time where IE stumbles, I decided to turn to
D. Flanagan's wonderful book
“JavaScript. A detailed guide ” (remembered that there was a chapter on debugging JavaScript. The proposed method coincided with what I was offered at work, but I decided to try again:
window.onerror = function (msg, url, line) {
alert(msg + "\n" + url + "\n" + "\n" + line);
return true ;
};
And here, this option worked! The error was safely found and fixed. It’s not clear why it didn’t help the first time. Perhaps it was because this function was first located in an external js file, the second time I placed it directly on the page - maybe this is what helped IE use it.
I hope that this experience will be useful to someone :-)