0

Currently using "react-native-webview": "^6.11.1" in application. While loading a website, there's a pop up which need to be approved. How can I enable/allow webview to display the pop up?

Tried on a few things:

  1. Setting prop useWebKit to TRUE (WkWebview) and FALSE (UIWebview)
  2. Setting prop onShouldStartLoadWithRequest to return true for every URL

To be more specific, the pop I mentioned looks like below when you run it on Desktop Chrome. There should be one pop up blocker notification requesting you to allow pop up. enter image description here

Tommy Leong
  • 2,509
  • 6
  • 30
  • 54
  • I'm suppose the direction of this is towards "createWebViewWithConfiguration" from WKWebView, this method suppose to trigger by `window.open()` – Tommy Leong Mar 23 '20 at 16:01

2 Answers2

3

TLDR;

Append the following code in RNCWKWebView.m under method didMoveToWindow

wkWebViewConfig.preferences.javaScriptCanOpenWindowsAutomatically = YES;
wkWebViewConfig.preferences.javaScriptEnabled = YES;

Btw, im using WKWebView.


Explanation

They key here is javaScriptCanOpenWindowsAutomatically which is actually set to NO as default value for iOS according to Apple docs

The default value is NO in iOS and YES in macOS.

Setting the this value to YES, indicates whether JavaScript can open windows without user interaction. In this case, I'm tackling with the window.open() function from my website's javascript.

Tommy Leong
  • 2,509
  • 6
  • 30
  • 54
0

this work for me on Android and IOS

javaScriptCanOpenWindowsAutomatically=true,

 <WebView
     javaScriptCanOpenWindowsAutomatically=true,
     source={{ uri: URL }}
      />
Deepak Singh
  • 749
  • 4
  • 16