Is it possible to open a site in an InAppBrowser, have that site use window.open
to open another window, then send a message to that other window (and vice versa)?
The InAppBrowser is a web browser view that displays when calling [window. open](window. open. html)() , or when opening a link formed as <a target="_blank"> .
There is no action to close the InAppBrowser. How can we achieve this? The user is redirected to an aws login page in the IAB and after suscessfull login the IAB should close and the user should be redirected to a screen in the app.
function openBrowser() { var url = 'https://cordova.apache.org'; var target = '_blank'; var options = "location = yes" var ref = cordova. InAppBrowser. open(url, target, options); ref. addEventListener('loadstart', loadstartCallback); ref.
Postmessage is already implemented on not released version. You can fork the most recent dev version on inAppBrowser from their git page: https://github.com/apache/cordova-plugin-inappbrowser/ Before building it remember to remove the current component and add the most recent dev version for using it. As its described in their documentation you can dispatch postmessage like:
inAppBrowserRef.executeScript({ code: "\
var message = 'this is the message';\
var messageObj = {my_message: message};\
var stringifiedMessageObj = JSON.stringify(messageObj);\
webkit.messageHandlers.cordova_iab.postMessage(stringifiedMessageObj);"
});
Or from inside inAppBrowser's app its something like:
const message = 'message'
const messageObj = {message: message}
const stringifiedMessageObj = JSON.stringify(messageObj)
if (window.webkit && Window.webkit.messageHandlers) {
console.log('postmessage call on webkit')
window.webkit.messageHandlers.cordova_iab.postMessage(stringifiedMessageObj)
}
And you can listen for it inside cordova like:
this.inAppBrowserRef.on('message').subscribe((event) => {
console.log(' postmessage received')
const postObject:any = event
if(postObject.data.message){
console.log(postObject.data.message)
}
})
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With