Capturing Javascript Alert in Webbrowser Control

家住魔仙堡 提交于 2019-12-02 11:15:01

If you're looking to only trap script error dialogs that appear, I would recommend trapping the window.onerror DOM event. If you assign a handler for this event, the message, (script) file name and line number are passed as arguments, those are all things shown in the error dialog that pops up. Note that most users have scripting error dialogs switched off by default so it would be wise to honour this if the intended purpose is for a large audience.

I'm not sure if there's an easier way, I've only worked with the old COM WebBrowser component.

Just do this:

window.alert = function(txt) {
   // Do something
}

This will allow you to do a callback or anything else you want with the alert text.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!