Hi, guys, I have a webView in the fragment and when I open some url that belongs to, for example, twitter, the page is shown but I canβt open any external link that are provided in tweets. Those external links actually all have set
target="_blank"
and I have appropriate js script injected when
onPageFinished
is called:
webView.webViewClient = object : WebViewClient() {
override fun onPageFinished(view: WebView, url: String?) {
Timber.d("onPageFinished: url = $url")
view.loadUrl("javascript: var allLinks = document.getElementsByTagName('a'); if (allLinks) {var i;for (i=0; i<allLinks.length; i++) {var link = allLinks[i]; var target = link.getAttribute('target'); if (target && target == '_blank') { link.removeAttribute('target');}}}")
}
This handling works for websites that provide their content immediately and this function is called when actual page loading is finished, but loading tweets is done asynchronously long after that. Does anyone have any idea how can I handle those newly injected urls in the page and change their
target
attributes ?