How to close a webview from a button inside the webview html page?

I have tried to close the webview with the HTML content is loading in the web view, It has a button on its click, I am triggering postMessage close event, and It’s working while I was checking in the web browser, but when tried in the Android Device, It’s stopped working.

HTML PAGE
Close WebView

Close WebView New

Close Test

COCOS Creator script,
this.node.on(‘InterstitialClosed’, () => {
console.log(‘Button clicked in WebView!’);
this.hideInterstitial();
}, this);

// capture the event for close Interstitial.
window.addEventListener('message', (event) => {
  if (event.data && event.data.type === 'close') {
    console.log("Button Clicked.");
    // Trigger a custom event in Cocos Creator
    this.node.emit('InterstitialClosed');
  }
});

Is there any other way to close the webview by the click on the webview HTML button?

Also want to know, Is this possible to open the links attached inside the HTML content should open on the device browser instead of loading in webview it self?

It could be done. I’ve done it before.
You just need to pre-register a scheme.

BTW, you should create your post under the correct category so that people will notice and help you.

Refer to this:

https://docs.cocos.com/creator/manual/en/ui-system/components/editor/webview.html#webview-internal-pages-call-external-code

@StudioAMK I have tried this, but it’s not working.

share me your code and how did you test? on the device?

Okay @StudioAMK, I will share my code tomorrow.

Hi @StudioAMK

It doesn’t allow me to share files here as I am new here on cocos forum, that’s why I thought I will upload on g-drive and will share with you, but it doesn’t support URL sharing too.

Please share your email address to send my source code and will further connect with you, because I urgently need support on cocos web-view.

Thanks

Please contact me at rohit.lalwani@5exceptions.com.