android端添加返回方法

This commit is contained in:
zher52 2020-09-10 16:08:05 +08:00
parent bb76e20464
commit 0aebf7c325
2 changed files with 17 additions and 0 deletions

View File

@ -337,6 +337,20 @@ public class InAppBrowser extends CordovaPlugin {
pluginResult.setKeepCallback(true); pluginResult.setKeepCallback(true);
this.callbackContext.sendPluginResult(pluginResult); this.callbackContext.sendPluginResult(pluginResult);
} }
else if(action.equals("back")){
this.cordova.getActivity().runOnUiThread(new Runnable() {
@SuppressLint("NewApi")
@Override
public void run() {
if(canGoBack()) {
goBack();
} else {
closeDialog();
}
}
});
}
else { else {
return false; return false;
} }

View File

@ -60,6 +60,9 @@
hide: function (eventname) { hide: function (eventname) {
exec(null, null, 'InAppBrowser', 'hide', []); exec(null, null, 'InAppBrowser', 'hide', []);
}, },
back: function(eventname) {
exec(null, null, 'InAppBrowser', 'back', []);
},
addEventListener: function (eventname, f) { addEventListener: function (eventname, f) {
if (eventname in this.channels) { if (eventname in this.channels) {
this.channels[eventname].subscribe(f); this.channels[eventname].subscribe(f);