Skip to content

Instantly share code, notes, and snippets.

@brownsoo
Last active February 21, 2020 06:48
Show Gist options
  • Select an option

  • Save brownsoo/6bda2c46223456884a0c6b97c239e6b3 to your computer and use it in GitHub Desktop.

Select an option

Save brownsoo/6bda2c46223456884a0c6b97c239e6b3 to your computer and use it in GitHub Desktop.
Android WebView handling _blank target link
override fun onCreateWindow(view: WebView?, isDialog: Boolean,
isUserGesture: Boolean, resultMsg: Message?): Boolean {
val context = view?.context ?: return false
val transport = resultMsg?.obj as? WebViewTransport
val newWebView = WebView(context)
view.addView(newWebView)
transport?.webView = newWebView
resultMsg?.sendToTarget()
newWebView.webViewClient = object : WebViewClient() {
override fun shouldOverrideUrlLoading(view: WebView, url: String): Boolean {
val uri = AppUtil.parseOrNull(url)
if (uri?.handleOpenWebView(context) == true) {
return true
}
return false
}
}
return true
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment