Iphone PhoneGap儿童浏览器执行JavaScript

Iphone PhoneGap儿童浏览器执行JavaScript,iphone,browser,cordova,Iphone,Browser,Cordova,我想知道这是否可以在phonegap儿童浏览器窗口内执行JavaScript,以便我们可以在phonegap应用程序下操作网站 从全局来看,我们可以在Objective-C中创建一个函数,将JS执行到childbrowser中(修改childbrowser.m和childbrowser.h文件),并创建它的JS包装器,以便调用JS函数在childbrowser中执行JS 我想让你们修改ChildBrowser让我拥有那个功能,这样我就不会迷失方向了。至少给我初步的步骤。好吧,我刚试过,一次成功。

我想知道这是否可以在phonegap儿童浏览器窗口内执行JavaScript,以便我们可以在phonegap应用程序下操作网站

从全局来看,我们可以在Objective-C中创建一个函数,将JS执行到childbrowser中(修改childbrowser.m和childbrowser.h文件),并创建它的JS包装器,以便调用JS函数在childbrowser中执行JS


我想让你们修改ChildBrowser让我拥有那个功能,这样我就不会迷失方向了。至少给我初步的步骤。

好吧,我刚试过,一次成功。太棒了!我刚刚修改了PhoneGap的ChildBrowser插件,它成功了

已更新

我终于有几分钟的时间为那些遇到同样问题的人更新答案

ChildBrowserCommand.h

- (void) jsExec:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options;
ChildBrowserCommand.m

- (void) jsExec:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options; {
    [childBrowser executeJS:(NSString *)[arguments objectAtIndex:0]];
}
ChildBrowserViewController.h

- (void)executeJS:(NSString *)js;
ChildBrowserViewController.m

- (void) executeJS:(NSString *)js {
    [webView stringByEvaluatingJavaScriptFromString:js];
}
ChildBrowser.js

/* MIT licensed */
// (c) 2010 Jesse MacFadyen, Nitobi

function ChildBrowser()
{

}

// Callback when the location of the page changes
// called from native
ChildBrowser._onLocationChange = function(newLoc)
{
    window.plugins.childBrowser.onLocationChange(newLoc);
}

// Callback when the user chooses the 'Done' button
// called from native
ChildBrowser._onClose = function()
{
    window.plugins.childBrowser.onClose();
}

// Callback when the user chooses the 'open in Safari' button
// called from native
ChildBrowser._onOpenExternal = function()
{
    window.plugins.childBrowser.onOpenExternal();
}

// Pages loaded into the ChildBrowser can execute callback scripts, so be careful to 
// check location, and make sure it is a location you trust.
// Warning ... don't exec arbitrary code, it's risky and could cause your app to fail.
// called from native
ChildBrowser._onJSCallback = function(js, loc)
{
    // Not Implemented
    window.plugins.childBrowser.onJSCallback(js, loc);
}

/* The interface that you will use to access functionality */

// Show a webpage, will result in a callback to onLocationChange
ChildBrowser.prototype.showWebPage = function(loc)
{
    PhoneGap.exec("ChildBrowserCommand.showWebPage",loc);
}

// close the browser, will NOT result in close callback
ChildBrowser.prototype.close = function()
{
    PhoneGap.exec("ChildBrowserCommand.close");
}

// Not Implemented
ChildBrowser.prototype.jsExec = function(jsString)
{
    // Not Implemented!!
    PhoneGap.exec("ChildBrowserCommand.jsExec", jsString);
}

// Note: this plugin does NOT install itself, call this method some time after deviceready to install it
// it will be returned, and also available globally from window.plugins.childBrowser
ChildBrowser.install = function()
{
    if(!window.plugins)
    {
        window.plugins = {};    
    }

    window.plugins.childBrowser = new ChildBrowser();
    return window.plugins.childBrowser;
}
我的全局变量

var CB = null;
在我的魔鬼节上

CB = ChildBrowser.install();
if (CB != null) {
    CB.onLocationChange = onCBLocationChanged;
}
我可以执行任何JS到网页使用

CB.jsExec("alert('I am from ChildBrowser!');");

我希望我的贡献能给你带来微笑。

你能分享一下你修改ChildBrowser插件的一些做法吗?是的,我当然可以分享,但如何分享?事实上,我很愿意分享,因为当你能帮助别人时,感觉真的很好,但问题是我无法处理Git,我对此一无所知。我以前使用过Git,但使用的是像“尝试并失败”这样的老派方法。我想以专业的方式学习Git,因为我目前正在取得成功。至少现在我知道它是怎么工作的了。我将很快更新我的许多东西,让公众知道它们就在我的硬盘里。