Tuesday, 25 August 2015

android webview, onPageFinished


Most of time we do call js in "onPageFinished" because "shouldOverrideUrlLoading" is too early.

But, sometime, "onPageFinished" is also too early to call js to modify html doms.

Especially if you have an iframe.

It is not a good idea to add onload function on document and iframe document. Because it is not reliable. Sometime "onPageFinished" is quick enough, the html docuement already finished "onload" lifecycle phase. Then your onload function call not get called.

So I suggest use this:


javascript:(function() {   var xxxddd = function() {      var iframeDom = document.getElementsByName("asdfasf")[0];
      console.log('iframeDom=' + iframeDom);
      if (iframeDom == undefined) {
         setTimeout( xxxddd, 1000 );
         return;
      }
      var iframeDocument = iframeDom.contentWindow.document;
      var xxxDom = iframeDocument.getElementById("xxxx");
      console.log('xxxDom =' + xxxDom);
      if (xxxDom == undefined) {
         xxxDom.value= "6444";
         setTimeout( xxxddd, 1000 );
         return;
      }
      xxxDom.value= "6444";
   };   xxxddd();})();











No comments:

Post a comment