小编Mut*_*nan的帖子

在React Native ios WebView的所有iframe中注入javascript

我正在使用react-native-webview加载具有多个 iframe 的 URL。我正在使用该方法将 javascript 注入到加载的网站中injectedJavaScript。该代码仅注入顶部框架中,而不注入 iframe 中。

对于 android,我重写了public WebResourceResponse shouldInterceptRequest(WebView view, WebResourceRequest request)拦截 HTML 并将所需的 Javascript 添加到其中的方法。

对于 iOS,经过一些谷歌搜索后,我发现一些结果指向设置forMainFrameOnly为“否”。我对 Objective C 完全是菜鸟,完全不知道如何设置它。我查看了 RNCWKWenView.m 文件,其中有forMainFrameOnly:YES2 个位置。我将 YES 替换为 NO,然后在 xcode 中重建我的 iOS 项目。但仍然无法在 iframe 中获取我的 javascript。

重现: App.js 文件

import React, { Component } from 'react';
import { BackHandler, Platform } from 'react-native';
import { WebView } from 'react-native-webview';

const WEBVIEW_REF = 'webview';

export default class App extends Component …
Run Code Online (Sandbox Code Playgroud)

android ios wkwebview react-native

5
推荐指数
1
解决办法
1755
查看次数

标签 统计

android ×1

ios ×1

react-native ×1

wkwebview ×1