Read Javascript variable from Web Browser control

后端 未结 6 735
攒了一身酷
攒了一身酷 2020-12-01 19:04

I am trying to read the value of a Javascript variable which is loaded and called from a WebBrowser control on my form.

Example:

index.html refers to a javas

6条回答
  •  春和景丽
    2020-12-01 19:30

    I think this is really a scoping question. If you include a file called test.js and in that file you have this line:

    var myVariable;
    

    Then that variable is created with global scope and is accessible from anywhere in your page and also in any other JavaScript files that you include. If you declare a variable like that, outside of a function, it will be created with global scope.

    One thought. If you're not able to access your variable in your main page then make sure that your script that declares it and assigns a value is included before the JavaScript on your page tries to use it. You could have an order of execution problem.

提交回复
热议问题