javascript - Dynamically adding multiple events to multiple webviews -


im new using electron , kinda new using webview tag, pre-apologize maybe not knowing obvious.

im trying dynamiclly create web views , add following events them.

did-start-loading did-stop-loading did-finish-load page-title-updated dom-ready im using mix of jquery , pure javascript im not having luck. have attached code below can try find obvious there. im not getting javascript errors in debug menu @ same time none of seems working.

function addtab(url){ tabcount++; var newtab = '<li href="#content-' + tabcount + '" id="tab' + tabcount + '" class="current"><img src="system_assets/icons/logo.png" /><span>tab home</span><a class="tabclose" href="#"></a></li>'; var newcontent = '<div id="content-' + tabcount + '" class="contentholder" style="display:block;"><webview id="webview-content-' + tabcount + '" src="http://www.ohhaibrowser.com"></webview></div>'; changecurrent(""); //hide current tabs $(".contentholder").css("display", "none"); //show new tab $("#tabs-menu").append(newtab); $("#browserwin").append(newcontent); $("#curwebwin").val("webview-content-" + tabcount); addlisteners("webview-content-" + tabcount,"tab" + tabcount); updatetabcount(); }  function updatetabcount(){ $("#hideshow").text(tabcount); }  function addlisteners(webview,tabid) { element = document.getelementbyid(webview);  element.addeventlistener("did-start-loading", function() {     loadstart(tabid); });  element.addeventlistener("did-stop-loading", function() {     loadstop(tabid,webview); });  element.addeventlistener("did-finish-load", function() {      loadstop(tabid,webview); });   element.addeventlistener("page-title-updated", function() {      loadstop(tabid,webview); });  element.addeventlistener("dom-ready", function() {      domloaded(tabid,webview); });  }  function loadstart(tabid) { $("#" + tabid + " span").val('loading...'); //$("#" + tabid + " img") }  function loadstop(tabid, webview) { $("#" + tabid + " span").val(''); }  function domloaded(tabid, webview) { element = document.getelementbyid(webview); $("#" + tabid + " span").val(element.geturl()); } 

you have set preload call make change in webview

browser.html

 <script src="browser.js"></script>  <webview src="https://www.google.com/watch?v=1osdnkzj-1k" preload="./inject.js" style="width:640px; height:480px"></webview> 

create sample js file name called inject.js

inject.js

__myinjection={ onloada : function() { var script = document.createelement("script"); script.src = "https://code.jquery.com/jquery-2.1.4.min.js"; $("#header").html('<h1>sample work</h1>\      <p>hello, google</p>\      <a href="anand">click me</a>');  document.body.appendchild(script);  }  } 

now in browser.js

onload = function() { var webview = document.queryselector('webview');  webview.addeventlistener("dom-ready", function(){     webview.executejavascript('__myinjection.onloada ()')      // webview.opendevtools(); });  dolayout(); 

Comments

Popular posts from this blog

html - Styling progress bar with inline style -

java - Oracle Sql developer error: could not install some modules -

How to use autoclose brackets in Jupyter notebook? -