Allow explicit target for Linking.openURL(), default to "_blank"#2277
Closed
avanwinkle wants to merge 2 commits intonecolas:masterfrom
Closed
Allow explicit target for Linking.openURL(), default to "_blank"#2277avanwinkle wants to merge 2 commits intonecolas:masterfrom
avanwinkle wants to merge 2 commits intonecolas:masterfrom
Conversation
Maker-Mark
reviewed
Apr 22, 2022
Comment on lines
-94
to
+98
| window.open(urlToOpen, '_blank', 'noopener'); | ||
| window.open(urlToOpen, string, 'noopener'); |
necolas
pushed a commit
that referenced
this pull request
Jun 9, 2022
necolas
pushed a commit
that referenced
this pull request
Jun 9, 2022
rnike
pushed a commit
to VeryBuy/react-native-web
that referenced
this pull request
Sep 13, 2022
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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, includingundefined. 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 atarget, 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 atargetwill get the new behavior.Also, tests added!