0

I would like to invoke a Javascript function on a web page that does not have a function 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>
FishBasketGordo
  • 22,904
  • 4
  • 58
  • 91
Paul
  • 177
  • 1
  • 5
  • 14

3 Answers3

4

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.

SLaks
  • 868,454
  • 176
  • 1,908
  • 1,964
2

As long as this closure does not export methods to the global namespace, you can't

topek
  • 18,609
  • 3
  • 35
  • 43
0

Expose a Method.

<script type="text/javascript"> 
(function(){
    MyFunction = function() {
      SOME CODE HERE;
    }
})();
</script>


Webbrowser.Document.InvokeScript("MyFunction");
Michael D. Irizarry
  • 6,186
  • 5
  • 30
  • 35