MouseEvent undefined in .NET WebBrowser control

℡╲_俬逩灬. 提交于 2019-12-25 08:15:26

问题


Why this is happening and how to fix this issue ?

Here is what's happening. A error is thrown by WebBrowser control which says :
An error has occureed in the script in this page.
Error: 'MouseEvent is undefined'

SetFeatureBrowserFeature("FEATURE_BROWSER_EMULATION", 9999);
//This forces my WebBrowser control to use IE9+ which in my case it's using IE 10

        var anyScripts = webBrowser1.Document.GetElementsByTagName("script");

        if (anyScripts == null || anyScripts.Count == 0) webBrowser1.Document.Body.AppendChild(webBrowser1.Document.CreateElement("script"));

        object f = webBrowser1.Document.InvokeScript("eval", new[] {
                        @"
function simulateClick() {
  var event = new MouseEvent('click', {
    'view': window,
    'bubbles': true,
    'cancelable': true
  });
  var cb = document.getElementById('rrx'); 
  var canceled = !cb.dispatchEvent(event);
  if (canceled) {
    // A handler called preventDefault.
    alert('canceled');
  } else {
    // None of the handlers called preventDefault.
    alert('not canceled');
  }
}; simulateClick();"
                    });

来源:https://stackoverflow.com/questions/21897880/mouseevent-undefined-in-net-webbrowser-control

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