Skip to content
This repository has been archived by the owner on Aug 1, 2024. It is now read-only.

Commit

Permalink
Open URL in new tab instead of new window to fix the URL flow.
Browse files Browse the repository at this point in the history
RELNOTES: Introduces a workaround for window.open(..., 'noopener') which will cause the the URL to open in a new browser window with no bookmark bar or ability to add tabs. This is a known issue tracked here: whatwg/html#1902

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=172163219
  • Loading branch information
John Plaisted committed Oct 19, 2017
1 parent b4e7246 commit 23b7a6c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
7 changes: 7 additions & 0 deletions closure/goog/window/window.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ goog.window.open = function(linkRef, opt_options, opt_parentWin) {
sb.push(option + '=' + opt_options[option]);
break;
case 'target':
case 'noopener':
case 'noreferrer':
break;
default:
Expand Down Expand Up @@ -224,6 +225,12 @@ goog.window.open = function(linkRef, opt_options, opt_parentWin) {
} else {
newWin = parentWin.open(
goog.html.SafeUrl.unwrap(safeLinkRef), target, optionString);
// Passing in 'noopener' into the 'windowFeatures' param of window.open(...)
// will yield a feature-deprived browser. This is an known issue, tracked
// here: https://github.com/whatwg/html/issues/1902
if (opt_options['noopener']) {
newWin.opener = null;
}
}
// newWin is null if a popup blocker prevented the window open.
return newWin;
Expand Down
14 changes: 14 additions & 0 deletions closure/goog/window/window_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -382,3 +382,17 @@ function testOpenNoReferrerEscapesUrl() {
'Does not contain expected HTML-escaped string: ' + documentWriteHtml,
/hello&world/, documentWriteHtml);
}

function testOpenNewWindowNoopener() {
newWin = goog.window.open(
REDIRECT_URL_PREFIX + 'theBest', {'target': '_blank', 'noopener': true});

// This mode cannot return a new window.
assertNotNull(newWin);
assertNotEquals(undefined, newWin.document);
assertNull(newWin.opener);

return waitForTestWindow(newWin).then(function(win) {
verifyWindow(win, false, 'theBest');
});
}

0 comments on commit 23b7a6c

Please sign in to comment.