在本机反应中,当单击网站中在新选项卡或新窗口中打开的任何链接时,WebView 会转到浏览器而不是覆盖 WebView

问题描述 投票:0回答:3

在 React Native WebView 中,在 WebView 中,单击在新水龙头或新窗口中打开的链接时出现问题,WebView 将我们的应用程序重定向到浏览器,但我希望应用程序不重定向到浏览器,WebView 覆盖链接。请解决问题,我很为你着想......

当单击网站中的任何链接时,这些网站会从我们的 React Native 应用程序重定向到我们的浏览器

import React, { useState } from 'react';
import WebView from 'react-native-webview';

const App = () =>{

return(
<WebView
 source={{uri:"https://www.coeju.com"}}

 />
  );
}


export default App;
reactjs webview native
3个回答
6
投票

setSupportMultipleWindows={false} 将其添加到您的 webview 属性中。 要了解更多信息,请访问下面的链接。

https://github.com/react-native-webview/react-native-webview/blob/master/docs/Reference.md#setsupportmultiplewindows

<WebView
  {...restProps}
  source={{uri}}
  onLoadStart={()=>setloading(true)}
  onLoadEnd={()=>setloading(false)}
  onLoad={()=>setloading(false)}
  style={{ flex: 1 }}
  injectedJavaScript={INJECTEDJAVASCRIPT}
  scrollEnabled
  setSupportMultipleWindows={false} //This will solve your problem
>


1
投票

据我了解,您可以阻止 webview 重定向到外部浏览器并捕获已按下的 URL,并通过将其存储在状态中来替换当前的 URI。

你可以尝试使用 webview 的 onShouldStartLoadWithRequest 属性

const[uri,seturi]=useState('https://stackoverflow.com/')

<WebView
 source={{uri}}
 onShouldStartLoadWithRequest={request => {
  if (request.url.includes('https')) {
      seturi(request.url);
      return false;
  } else return true;
 }}
 />

0
投票

setSupportMultipleWindows 标志仅适用于 Android,如果您也想在 ios 中启用多个屏幕,那么您需要将 useWebView2 启用为 true,以决定 Web 视图是否应使用新的基于 chromium 的边缘 webview 并将 javaScriptCanOpenWindowsAutomatically 启用为 true。 希望能帮助您解决这个问题

useWebView2={true} javaScriptCanOpenWindowsAutomatically={true}

© www.soinside.com 2019 - 2024. All rights reserved.