shouldOverrideUrlLoading

shouldOverrideUrlLoading

本文介绍了的WebView检测点击iframe中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个web视图我在哪里加载一个JavaScript加载一些内容。该内容是一个iframe的HTML。

I have a WebView where I am loading a javascript that loads some content. That content is an html with an iframe.

这似乎在IFRAME不触发调用 WebViewClient#shouldOverrideUrlLoading(web视图查看,字符串URL)的任何点击; web视图设置了两个 WebViewClient WebChromeClient

It seems any click within iframe is not triggering calls to WebViewClient#shouldOverrideUrlLoading(WebView view, String url); The webview has set both WebViewClient and WebChromeClient.

一个变通办法,我可以看到的是调用的getSettings()。setSupportMultipleWindows(真)上的WebView然后在 onCreateWindow(web视图看来,布尔选录,布尔isUserGesture,信息resultMsg)假设呼叫是在iframe中取得并使用一些插入JavaScript才能获得iframe的数据。但是,这似乎是丑陋的我。

A work-around I can see of is to call getSettings().setSupportMultipleWindows(true) on the WebView and then within onCreateWindow(WebView view, boolean isDialog, boolean isUserGesture, Message resultMsg) assume the call was made within iframe and use some inserted javascript in order to get the iframe data. But that seems ugly to me.

所以,问题:你怎么发现在iframe中的WebView中加载一个点击

So, the question: how do you detect a click within iframe loaded within the webview?

谢谢!

推荐答案

我想我已经发现有什么问题:我打破了的。这是做Web开发的同事向我指出了正确的方向。

I think I have found what is the problem: I broke the Same Origin Policy. A colleague that is doing web development pointed me in the right direction.

整个文档(包含的iFrame)具有不同的原点(方案,主机名和端口号的组合)比包含iframe中。只要这些帧(包含文件和内部的iframe)有不同的来源,它们将无法通信。这就是为什么我没有得到调用 shouldOverrideUrlLoading

The whole document (containing the iFrame) has a different origin (combination of scheme, host name and port number) than containing iframe. As long as those frames (containing document and inner iframe) have different origins, they cannot communicate. That's why I am not getting calls to shouldOverrideUrlLoading.

修改:好像有一种方法立交桥上面的安全策略,但是自带的公认的安全风险:添加下面的标题中包含iframe的回应:访问 - 控制 - 允许 - 产地:*

EDIT: It seems there is a way to overpass above security policy, but that comes with accepted security risk: Add the following header in the response that contains the iframe: "Access-Control-Allow-Origin:*"

这篇关于的WebView检测点击iframe中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-26 18:42