Reputation: 421
i have got such a problem here:
i have a webpage in webbrowser control. that page uses javascript and had subscribed to number of events (i.e. click).
here is algorithm that needed:
is there anyway to do that?
thanks in advance.
Upvotes: 1
Views: 824
Reputation: 15616
1. method: create the unsubscription functions in javascript and then call it from c# side,
in the page code:
<script type="text/javascript">
// assign the event to the element
document.getElementById("myElem").onclick = function(){
//your code here
}
// clear the event
function clearEvent(){
document.getElementById("myElem").onclick = function(){
return false;
}
}
</script>
in C# side:
IHTMLDocument2 doc = (IHTMLDocument2)IE.Document;
IHTMLWindow2 parentWindow = doc.parentWindow;
if (parentWindow != null)
parentWindow.execScript("clearEvent();", "javascript");
}
2. method: call the unsubscription code directly from c#
IHTMLDocument2 doc = (IHTMLDocument2)IE.Document;
IHTMLWindow2 parentWindow = doc.parentWindow;
if (parentWindow != null)
parentWindow.execScript("document.getElementById('myElem').onclick=function(){return false;}", "javascript");
}
Upvotes: 1