Android Question WebView..How to handle popups?

Indy

Active Member
Licensed User
Longtime User
Hi

I'm using a WebView to open a webpage which contains various sections that open in a second window. I've got the popup opening fine using the following;

B4X:
WebViewSt.SetJavaScriptCanOpenWindowsAutomatically(WebView0,True)
WebViewSt.getJavaScriptCanOpenWindowsAutomatically(WebView0)

BTW - The above depends on the WebViewSettings library.

However, the issue I have is that on the popup page there is a button that which you can use to close the window and allowing you to return control back to the parent window. Now I'm not sure if what I've done is correct because when I press the button nothing happens. I suppose what it's trying to do is close the WebView which presumably cannot happen.

So my question is, how should I be handling opening a child window using WebViews?

Thanks
 

Indy

Active Member
Licensed User
Longtime User
I'm not sure whether it is implemented in any of the WebView libraries.

Funny you mention this as I just found a library called "WebViewExtras" by WarWound which has a method called "addWebChromeClient", which I kind of assume does what you describe. However, I don't know how it works which means I don't know how to use it. Anyway, having looked through various posts on the library and examples of code, I've now added the following line to me code;

B4X:
WebViewEx.addWebChromeClient(WebView0,"")

Now when I run the app I get a whole host of errors, which I will come back to but, one in particular kind of stands out.

Scripts may close only the windows that were opened by it. in https://**************** (Line: 66)

It looks like that we're heading in the right direction as now I can see that the close button on the popup is being trapped where before there was nothing. Do you think the error could be because I'm not opening the popup in another WebView and therefore the code (javacsript) has nothing to go back to?

Thanks
 
Upvote 0
Top