开发者

How do I invoke a Javascript that does not have a name using C#

开发者 https://www.devze.com 2023-04-10 07:03 出处:网络
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

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");
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号