当单击网站中的任何链接中,在新标签或新窗口中打开的任何链接时,webview in react Native in react Native in New Tab或New窗口中的任何链接都将用于浏览器在WebView上不覆盖

发布于 2025-01-30 19:17:56 字数 424 浏览 3 评论 0原文

在React Native WebView中,在WebView中,当单击新的Tap或New窗口打开的链接时,WebView将我们的应用程序重定向到浏览器时,就会发生问题,但我希望应用程序不重定向以浏览WebView覆盖链接。请解决问题,我对您非常考虑....

当点击网站上的任何链接,这些网站网站从我们的React Native App重定向到我们的浏览器

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

const App = () =>{

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

 />
  );
}


export default App;

In React native WebView , In webview there was a problem occur when click on link which open in new tap or new window ,the webview redirect our app to the browser but I want app not redirect to browser the webview override the link . Please solve the problem , I am very thinkful to you....

when click on any link in the website theses website redirect to our browser from our react native app

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

const App = () =>{

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

 />
  );
}


export default App;

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

尹雨沫 2025-02-06 19:17:56

setSupportMultipleWindows = {false}
将其添加到您的Webview道具中。
有关更多信息,请访问下面的链接。

https://github.com /react-native-webview/reaeact-native-native-webview/blob/master/docs/reference.md#setsupportmultmultiplewindows

<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
>

setSupportMultipleWindows={false}
add this in your webview props.
For more to know how this works, visit below link.

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
>

木格 2025-02-06 19:17:56

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

您可以尝试使用WebView的 onShoundStartLoadWithRequest

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;
 }}
 />

From what I understood you can prevent the webview to redirect to an external browser and capture the URL that has been pressed and replace the current URI by storing it in the state.

you can try using the onShouldStartLoadWithRequest props of webview

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;
 }}
 />
流殇 2025-02-06 19:17:56

您可以转到React-native-webview存储库,并为此查看更多功能。

简单地说,我在这里写下它。

<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
  useWebView2={true}//Function that is invoked when the `WebView` should open a new window.
  javaScriptCanOpenWindowsAutomatically={true}//A Boolean value indicating whether JavaScript can open windows without user interaction.

您可以从repo中查看更多信息。

https:// github。 com/react-native-webview/react-native-webview/blob/master/src/webviewtypes.ts#l793

You can go to react-native-webview repo and see some more functions for this.

For simple i am writing down it here.

<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
  useWebView2={true}//Function that is invoked when the `WebView` should open a new window.
  javaScriptCanOpenWindowsAutomatically={true}//A Boolean value indicating whether JavaScript can open windows without user interaction.

You can check more about it from repo.

https://github.com/react-native-webview/react-native-webview/blob/master/src/WebViewTypes.ts#L793

硬不硬你别怂 2025-02-06 19:17:56

SetSupportMultipleWindows标志仅在您要启用iOS中的Muliple屏幕时才适用于Android,那么您需要启用UseWebView2,以使usewebview2 true true,以确定Web视图是否应使用新的基于铬的gend Web视图和启用Javascriptcancancriptcancanopenwindowsautomation holical holical holical holical holical holical holical homical holical holical homical holical holical holical holical homical in tirm thrue。
我希望它能帮助您解决此问题

   useWebView2={true}

   javaScriptCanOpenWindowsAutomatically={true}

setSupportMultipleWindows flag works for android only if u want to enable muliple screens in ios as well then u need to enable useWebView2 to true that detenmines whether the web view should use the new chromium based edge webview and enable javaScriptCanOpenWindowsAutomatically to true.
I hope it will help you to fix this issue

   useWebView2={true}

   javaScriptCanOpenWindowsAutomatically={true}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文