问题描述
我采用了android web视图加载URL。它的工作很好,但问题是某些网页中的链接(TARGET = _blank)不开放的默认方式。我调试项目,发现这些链接不调用webviewclient shouldoverrideurlloading()()方法。
这是webviewclient,
公共类MyWebClient扩展WebViewClient { @覆盖
公共布尔shouldOverrideUrlLoading(的WebView视图,字符串URL){
view.loadUrl(URL);
返回true; }
}
我发现,如果你是在一个运行的 IFRAME
, shouldOverrideUrlLoading()
则不会触发对外部链接,除非您添加目标=_顶
(我没有尝试目标= _blank
)。
下面的JavaScript code会将此目标属性,每一个环节。
函数change_links_target()
{
变种all_document_links = mFrameDocument.getElementsByTagName(一);
对于(i = 0; I< all_document_links.length;我++){
all_document_links [I] .setAttribute(目标,_top);
}
}
I'm using android web view to load a url. it's working fine but the problem is some of the links (target=_blank) inside the web page not opening default way. i debug the project and found these links not calling shouldoverrideurlloading() method in webviewclient().
this is webviewclient,
public class MyWebClient extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
}
I found that if you are running in an iframe
, shouldOverrideUrlLoading()
is not triggered for external links, unless you add target="_top"
(I didn't try target="_blank"
).
The following JavaScript code adds this target attribute to each link.
function change_links_target()
{
var all_document_links = mFrameDocument.getElementsByTagName("a");
for (i = 0; i < all_document_links.length; i++){
all_document_links[i].setAttribute("target", "_top");
}
}
这篇关于Android的Web视图 - shouldoverrideurlloading不叫的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!