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 printer. When the state of the printer changes, it triggers an event in .NET.
Then, I call a JavaScript method OnPrinterStateChanged(state)
with the InvokeScript
function of the WebBrowser control.
The problem is that I have to implement the method OnPrinterStateChanged(state)
in my webpage. I can't change the name of the method or subscribe/unsubscribe to the event...
I would like to move the JavaScript method OnPrinterStateChanged(state)
in a separate JavaScript file.
What I want :
- Subscribe/Unsubscribe to the event in my HTML page and decide what I want to do when the event is triggered (ex. : "function ChangeState")
- When the .NET event is triggered, it calls the
OnPrinterStateChanged(state)
of my separate .js file, then the JavaScript event is triggered and the functionChangeState
is called.
I found some solutions but I didn't manage to make it work... What is the simplest way to do it?