Sign Up

Sign In

Forget Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

You must login to ask question.

Open Url in default web browser

  • 0

I am new in react-native and i want to open url in default browser like Chrome in Android and iPhone both.

We open url via intent in Android same like functionality i want to achieve.

I have search many times but it will give me the result of Deepklinking.

Share This Post
Share
  1. Example from the docs:

    class OpenURLButton extends React.Component {
      static propTypes = { url: React.PropTypes.string };
      handleClick = () => {
        Linking.canOpenURL(this.props.url).then(supported => {
          if (supported) {
            Linking.openURL(this.props.url);
          } else {
            console.log("Don't know how to open URI: " + this.props.url);
          }
        });
      };
      render() {
        return (
          <TouchableOpacity onPress={this.handleClick}>
            {" "}
            <View style={styles.button}>
              {" "}<Text style={styles.text}>Open {this.props.url}</Text>{" "}
            </View>
            {" "}
          </TouchableOpacity>
        );
      }
    }

    Here’s an example you can try on Expo Snack:

    import React, { Component } from 'react';
    import { View, StyleSheet, Button, Linking } from 'react-native';
    import { Constants } from 'expo';
    
    export default class App extends Component {
      render() {
        return (
          <View style={styles.container}>
           <Button title="Click me" onPress={ ()=>{ Linking.openURL('https://google.com')}} />
          </View>
        );
      }
    }
    
    const styles = StyleSheet.create({
      container: {
        flex: 1,
        alignItems: 'center',
        justifyContent: 'center',
        paddingTop: Constants.statusBarHeight,
        backgroundColor: '#ecf0f1',
      },
    });
    • 0
Leave an answer

Leave an answer

Browse

close