mirror of
https://github.com/apache/cordova-android.git
synced 2025-02-22 00:32:55 +08:00
[CB-2305] Add InAppBrowser injectSriptCode command to support InAppBrowser.executeScript and InAppBrowser.insertCSS APIs
This commit is contained in:
parent
b028ad3604
commit
f60d54eae4
@ -151,6 +151,21 @@ public class InAppBrowser extends CordovaPlugin {
|
|||||||
pluginResult.setKeepCallback(false);
|
pluginResult.setKeepCallback(false);
|
||||||
this.callbackContext.sendPluginResult(pluginResult);
|
this.callbackContext.sendPluginResult(pluginResult);
|
||||||
}
|
}
|
||||||
|
else if (action.equals("injectScriptCode")) {
|
||||||
|
String source = args.getString(0);
|
||||||
|
|
||||||
|
org.json.JSONArray jsonEsc = new org.json.JSONArray();
|
||||||
|
jsonEsc.put(source);
|
||||||
|
String jsonRepr = jsonEsc.toString();
|
||||||
|
String jsonSourceString = jsonRepr.substring(1, jsonRepr.length()-1);
|
||||||
|
String scriptEnclosure = "(function(d){var c=d.createElement('script');c.type='text/javascript';c.innerText="
|
||||||
|
+ jsonSourceString
|
||||||
|
+ ";d.getElementsByTagName('head')[0].appendChild(c);})(document)";
|
||||||
|
this.inAppWebView.loadUrl("javascript:" + scriptEnclosure);
|
||||||
|
|
||||||
|
PluginResult pluginResult = new PluginResult(PluginResult.Status.OK);
|
||||||
|
this.callbackContext.sendPluginResult(pluginResult);
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
status = PluginResult.Status.INVALID_ACTION;
|
status = PluginResult.Status.INVALID_ACTION;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user