InAppBrowser inserts a script (using executeScript)

InAppBrowser js scripts using {code: 'some code'} param works fine, but not with the {file: 'local file url'} parameter.

 var ref = window.open('http://apache.org', '_blank', 'location=yes'); ref.addEventListener('loadstop', function() { ref.executeSript({file: "myscript.js"}); }); 

how do i start an injection script using param parameter to input my local js script?

  • Is an absolute file path or relative required?
  • Should the file be hosted on a child website?

This seems to be a mysterious complex thing, as I have several lines of script and cannot embed it all using ref.executeSript({codedetails, callback: "myscript.js"});

+6
source share
1 answer

I had the same problem. Using cordova3.1.0.

 ref.executeScript( { file: "http://ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js" //webURL works fine with 'file' }, function() { $.get("js/myscript.js", function(data) { //workaround to obtain code using jQuery.get ref.executeScript( { code: data }, function() { console.log('ref.executeScript done'); }); }); }); 

When I set the file url as webURL http: // ....,

it worked, but I could not figure out how to specify the local js file,

so I get lines of code using $ .get "js / myscript.js".

The sample code illustrates: jQuery is already installed in the phonegap application, and is also trying to use jQuery in the target inAppBrowser application. Just in case.

+5
source

Source: https://habr.com/ru/post/953232/


All Articles