Adewale George
Adewale George

Reputation: 279

InAppBrowser inject script (using executeScript)

InAppBrowser js scripts injection using {code: 'some code'} param is working perfectly but not with {file: 'local file url'} param.

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

how do I go about injecting script using the file param to inject my local js script?

It seem like a mysterious complicated thing to do as I have a few lines of script and can't embed it all using ref.executeSript({codedetails, callback: "myscript.js"});

Upvotes: 8

Views: 3828

Answers (1)

user1028880
user1028880

Reputation:

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 point the local js file,

so I obtain code strings using $.get "js/myscript.js".

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

Upvotes: 6

Related Questions