Last active
February 21, 2020 06:48
-
-
Save brownsoo/6bda2c46223456884a0c6b97c239e6b3 to your computer and use it in GitHub Desktop.
Android WebView handling _blank target link
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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