Created
October 12, 2011 08:32
-
-
Save akfish/1280652 to your computer and use it in GitHub Desktop.
C# Attach event to HTMLElement in webBrowser
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <summary> | |
/// Inject onclick handler to close button | |
/// </summary> | |
private void InjectJS() | |
{ | |
HtmlDocument doc = webContent.Document; | |
HtmlElement closeBtnElement = doc.GetElementById(CloseButtonId); | |
if (closeBtnElement == null) | |
return; | |
closeBtnElement.AttachEventHandler("onclick", new EventHandler(WebCloseButtonCallBack)); | |
} | |
/// <summary> | |
/// Called when close button is clicked | |
/// </summary> | |
/// <param name="sender"></param> | |
/// <param name="e"></param> | |
private void WebCloseButtonCallBack(Object sender, EventArgs e) | |
{ | |
//Do something here | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is nice. But how to detect if an event listener is already attached.