Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow explicit target for Linking.openURL(), default to "_blank" #2277

Closed

Conversation

avanwinkle
Copy link
Contributor

@avanwinkle avanwinkle commented Apr 12, 2022

This PR extends on the work started by @Sharcoux in PR #1743 and relates to issues #162, #1544, and #1744.

The desire of those tickets was to open Linking.openURL(url) in a new tab, and the solution merged by @necolas in this commit hard-codes the "_blank" target to force a new tab. This is great for people who want new tabs, but inconvenient for people who want to use the same tab.

This PR reworks the method to accept a second argument, Linking.openURL(url, target) for an explicit target. Any value passed will be used as the target, including undefined. The ability to pass undefined allows users to maintain the same browser tab, while arbitrary values allow... well, anything.

For backwards compatibility, if Linking.openURL(url) is called without a target, the default value of "_blank" will be passed. Therefore this change should have zero impact on any code already written, only users henceforth who explicitly pass a target will get the new behavior.

Also, tests added!

Comment on lines -94 to +98
window.open(urlToOpen, '_blank', 'noopener');
window.open(urlToOpen, string, 'noopener');

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Finally! Thanks for adding this :)

@necolas necolas added this to the 0.18: StyleSheet milestone May 18, 2022
@necolas necolas added the has: pr Subject of a pull request label Jun 8, 2022
necolas pushed a commit that referenced this pull request Jun 9, 2022
necolas pushed a commit that referenced this pull request Jun 9, 2022
@necolas necolas closed this in ffd300e Jun 10, 2022
rnike pushed a commit to VeryBuy/react-native-web that referenced this pull request Sep 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
has: pr Subject of a pull request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants