10 examples of 'react native open link in browser and return to app' in JavaScript

Every line of 'react native open link in browser and return to app' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
44async openLink() {
45 const { url, statusBarStyle } = this.state;
46 try {
47 if (await InAppBrowser.isAvailable()) {
48 // A delay to change the StatusBar when the browser is opened
49 const animated = true;
50 const delay = animated && Platform.OS === 'ios' ? 400 : 0;
51 setTimeout(() => StatusBar.setBarStyle('light-content'), delay);
52 const result = await InAppBrowser.open(url, {
53 // iOS Properties
54 dismissButtonStyle: 'cancel',
55 preferredBarTintColor: '#453AA4',
56 preferredControlTintColor: 'white',
57 readerMode: false,
58 animated,
59 modalPresentationStyle: 'fullScreen',
60 modalTransitionStyle: 'partialCurl',
61 modalEnabled: true,
62 enableBarCollapsing: false,
63 // Android Properties
64 showTitle: true,
65 toolbarColor: '#6200EE',
66 secondaryToolbarColor: 'black',
67 enableUrlBarHiding: true,
68 enableDefaultShare: true,
69 forceCloseOnRedirection: false,
70 // Specify full animation resource identifier(package:anim/name)
71 // or only resource name(in case of animation bundled with app).
72 animations: {
73 startEnter: 'slide_in_right',
74 startExit: 'slide_out_left',
75 endEnter: 'slide_in_left',
76 endExit: 'slide_out_right'
77 },
78 headers: {
79 'my-custom-header': 'my custom header value'
80 }
81 });
82 // A delay to show an alert when the browser is closed
83 await this.sleep(800);
84 Alert.alert('Response', JSON.stringify(result));
85 } else {
86 Linking.openURL(url);
87 }
88 } catch (error) {
89 Alert.alert(error.message);
90 } finally {
91 // Restore the previous StatusBar of the App
92 StatusBar.setBarStyle(statusBarStyle);
93 }
94}
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

7export async function open (url) {
8 const ok = await Linking.canOpenURL(url)
9 if (!ok) return false
10 const opened = await Linking.openURL(url)
11 return opened
12}
210openExternalLink(href) {
211 const a = document.createElement('a')
212 a.href = link
213 a.target='_blank'
214 a.click()
215}
157openLink(url: string) {
158 shell.openExternal(url);
159 trackEvent('Outbound Link', 'Click', url);
160}
51openUrl(url: string): Promise<any> {
52 return;
53}
270openLink({ href, target, currentTarget, metaKey }) {
271 let resolved = href || this.resolveHref(target || currentTarget);
272 if (!resolved) {
273 return;
274 }
275 if (target && target.closest('.no-open-link-events')) {
276 return;
277 }
278
279 let { protocol } = url.parse(resolved);
280 if (!protocol) {
281 protocol = 'http:';
282 resolved = `http://${resolved}`;
283 }
284
285 if (['mailto:', 'mailspring:'].includes(protocol)) {
286 // We sometimes get mailto URIs that are not escaped properly, or have been only partially escaped.
287 // (T1927) Be sure to escape them once, and completely, before we try to open them. This logic
288 // *might* apply to http/https as well but it's unclear.
289 const sanitized = encodeURI(decodeURI(resolved));
290 remote.getGlobal('application').openUrl(sanitized);
291 } else if (['http:', 'https:', 'tel:'].includes(protocol)) {
292 shell.openExternal(resolved, { activate: !metaKey });
293 }
294 return;
295}
90openUrl(urlToOpen) {
91 Linking.openURL(urlToOpen);
92}
306getDeferredApplink(): Promise<string> {
307 return;
308}
26export function openURL(url, title, showNavigationToolbar, requireLocationPermission) {
27 return navigateTo(getWebViewRoute(url, title, showNavigationToolbar, requireLocationPermission));
28}
48function openExternal (e, url) {
49 e.preventDefault()
50 shell.openExternal(url)
51}

Related snippets