VB.NET Gecko Web Browser javascript function calling? -


i using geckowebbrowser within vb.net (windows form app) program. geckowebbrowser loads local html file. html has embed in-line svg file (human body diagram bones , internal organs) javascript function picking "ids" of elements svg document. i'd call aforementioned javascript function vb.net (windows form app), don't know how so. can me, or give me source code example please? stuff i've found based in c#... javascript function in html file:

<script type="text/javascript">  (funcion () {  // function called in vb.net when dom loaded   var svghandler = function () {      // picking id root node="cuerpo_humano" svg variable      var svg = document.queryselector('#cuerpo_humano');       // in items save <g> have id      var items = svg.queryselectorall('g[id], path[id]');      //var items = svg.queryselectorall('g[id]');      // loop nodes saved in items , add them click event listener       foreach(items, function (index, value) {          value.addeventlistener('click', function (event) {                    event.preventdefault();                  //we avoid spread of events                 event.stoppropagation();                      return event.currenttarget.id                  // console.log(event.currenttarget.id)              });      });    }  // https://toddmotto.com/ditch-the-array-foreach-call-nodelist-hack/  var foreach = function (array, callback, scope) {    (var = 0; < array.length; i++) {      callback.call(scope, i, array[i]); // passes stuff need    }  };    // method, call svghandler when dom totally loaded   document.addeventlistener('domcontentloaded', svghandler);  })();  </script>  

what code should use in vb.net calling javascript function each time click on specific bone or organ in human body diagram loaded in geckowebbrowser? want save "id" picked calling string variable in order use parameter in sql statement , populate datagridview. i've been searching , find related c#, not single vb.net example. though trying figure out equivalence in vb.net trying convert c#'s examples vb.net, have doubts on how javascript call. according javascript function this:

browsercontrol.navigate("javascript:void(funcion())"); 

please, can me solve this? thankful...

well since have set click eventlistener's think you're not looking way call eventual function vb.net quite unclear according post i'll give examples on how call javascript function , how trigger reaction in vb.net code through javascript using geckowebbrowser.

your code snippet of attempt call js function vb code correct. problem haven't defined callable js function in html file. in case should trigger main js function vb:

//sorry don't know vb. i'll give example in c# keeping simple possible can convert vb  gecko.geckohtmlelement humanbodypart = (gecko.geckohtmlelement) browsercontrol.document.getelementbyid("your id"); humanbodypart.click(); 

the above code finds element matching id in geckowebbrowser , clicks it. since you've set click eventlistener's, clicking 1 of elements trigger function assigned them run.

moving on, in order save id of elements string variable in vb code you'll need add little bit of js code in code pass 'callback' parameter in foreach function:

var event = document.createevent('messageevent'); var origin = window.location.protocol + '//' + window.location.host; var event = new messageevent('jscall', { 'view': window, 'bubbles': false, 'cancelable': false, 'data': 'your eventual id string (this stuff goes vb/c# code)' }); document.dispatchevent (event); 

then above snippet should handled in vb code this:

browsercontrol.addmessageeventlistener("jscall", (id) => {    //here in variable id have clicked id string. wanted do... }); 

Comments

Popular posts from this blog

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -