skip to Main Content

i want to open a url with react native. But i dont want to go to the browser page.When i clicked button, it should open a url in the backgorund. But i want to stay in my app . Is there way to do it with expo?

I looked for result for a long time but did not found any solution about it.
I have tried background-feth, react native-linking, window.open and etc.

2

Answers


  1. Opening an URL in the background without switching to the browser page is a bit tricky in React Native (Expo) due to security and limitations. Expo does not provide a direct way to achieve this behavior as it goes against their security principles.

    However, you can use the InAppBrowser module to open a URL within your app. This module allows you to display web content inside your React Native app.

    you can refer to [this][1]

    You can install it using:

    expo install expo-in-app-browser
    

    For example:-

    import React from 'react';
    import { View, Button } from 'react-native';
    import * as WebBrowser from 'expo-in-app-browser';
    
    const App = () => {
      const openURL = async () => {
        try {
          await WebBrowser.openBrowserAsync('https://www.google.com', {
          });
        } catch (error) {
          console.error('Error opening URL', error);
        }
      };
    
      return (
        <View>
          <Button title="Open URL" onPress={openURL} />
        </View>
      );
    };
    
    export default App;
    
    Login or Signup to reply.
  2. To open an url within the app you may library. This library will display the website based on the url given while staying in the application.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search