InAppBrowser注入脚本(使用executeScript) [英] InAppBrowser inject script (using executeScript)

查看:1929
本文介绍了InAppBrowser注入脚本(使用executeScript)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

InAppBrowser js脚本注入使用 {code:'some code'} param工作正常,但没有 {file:'local file url' } param。

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"});
});

如何使用文件参数注入脚本来注入我的本地js脚本?

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


  • 是否需要绝对文件路径或相对文件?

  • 必须在子网站上托管文件吗?

这似乎是一件神秘的复杂事情,因为我有几行脚本并且无法使用<$ c $嵌入它们c> ref.executeSript({codedetails,callback:myscript.js});

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"});

推荐答案

我遇到了同样的问题。使用cordova3.1.0。

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');
            });
        });
    });

当我将文件URL设置为webURL http:// ....时,

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

它有效,但我无法弄清楚如何指向本地js文件,

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

因此我使用$获取代码字符串.getjs / myscript.js。

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

示例代码说明:jQuery已经安装在phonegap App上,并且还试图在目标inAppBrowser app上使用jQuery 。以防万一。

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.

这篇关于InAppBrowser注入脚本(使用executeScript)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆