1

I have a CodeName One app where I'm using the BrowserComponent to load an HTML page. This HTML page (HTMLPage1) further opens another HTML page (HTMLPage2) on the click of a button using window.open(). This works correctly in the app. This HTMLPage2 has a Close button and on clicking this button, HTMLPage2 should be closed and the control should go back to HTMLPage1. However, this is not working as expected. On clicking the Close button, nothing happens in the app and HTMLPage2 is still shown in the app. I have tried using window.close() and self.close() and neither of them work.

I found the following article on searching Android Webview: Scripts may close only the windows that were opened by it that seems similar to the problem I am facing

Also, I have a WebView Test app (can be found on PlayStore - search for com.snc.test.WebView Test) on my mobile that lets me modify the WebView settings and launch different URL's. I used this app to check if I can successfully invoke my HTML pages through the WebView Test app. With the default settings, I ran into the same problem as described above. The Close button didn't work. However, then I modified the setSupportMultipleWindows() property in the app and set it to true. After that, it worked correctly through the WebView Test app. On clicking Close in HTMLPage2, that page was closed and I could see HTMLPage1 again.

So, I tried checking how to set this property in CodeName One. I found that the BrowserComponent.setProperty("SupportMultipleWindows", "true") should be able to do the same thing. When I set this property and tested the app, it still didn't work. Then I looked through the documentation of
WebSettings.setSupportMultipleWindows

According to this documentation, if set to true, WebChromeClient.onCreateWindow(WebView, boolean, boolean, Message) must be implemented by the host application. I could not find a way to do this through CodeName One.

Am I going down the right path to tackle this problem? If not, kindly guide me.

Vitor M. Barbosa
  • 3,286
  • 1
  • 24
  • 36
Girish
  • 23
  • 5
  • I don't think that's a good idea. We might be able to do something for Android but then what about iOS/UWP? The `WebChromeClient` class is hidden in `AndroidImplementation.java` which you can find in http://github.com/codenameone/CodenameOne/ we can add this method (although not this week as we're entering code freeze for 5.0) but I don't know what the right implementation would be for something like this. – Shai Almog Sep 12 '18 at 03:34

0 Answers0