How do I invoke a Javascript that does not have a name using C#
I would like to invoke a Javascript function on a web page that does not have a f开发者_如何学JAVAunction name. Using C#, I would normally use Webbrowser.Document.InvokeScript("ScriptName")
. In this instance however, there is only a type attribute. This is what it looks like:
<script type="text/javascript">
(function(){
SOME CODE HERE;
})();
</script>
That is a self-invoking function.
It will run as soon as that statement is executed.
It is not possible to run it again without modifying the script.
As long as this closure does not export methods to the global namespace, you can't
Expose a Method.
<script type="text/javascript">
(function(){
MyFunction = function() {
SOME CODE HERE;
}
})();
</script>
Webbrowser.Document.InvokeScript("MyFunction");
精彩评论