Create JavaScript custom event

后端 未结 4 427
予麋鹿
予麋鹿 2020-12-02 09:56

I would like to create a custom event in JavaScript.

I have a WPF application with a WebBrowser inside, and a HTML page with JavaScript.

I work with a printe

4条回答
  •  粉色の甜心
    2020-12-02 10:23

    Ok I found a solution.

    I had to change the WebBrowser IE Version to Internet Explorer 11: http://weblog.west-wind.com/posts/2011/May/21/Web-Browser-Control-Specifying-the-IE-Version

    And then :

    function OnPrinterStateChanged(state) {
    
        var evt = document.createEvent("Event");
        evt.state = state;
        evt.initEvent("printerstatechanged", true, false);
        window.dispatchEvent(evt);
    
    }
    
    
    window.addEventListener('printerstatechanged', function (e) {
      // Do something
    });
    

提交回复
热议问题