| <!DOCTYPE html> |
| |
| <!-- Copyright 2016 The Chromium Authors. All rights reserved. |
| Use of this source code is governed by a BSD-style license that can be |
| found in the LICENSE file. --> |
| |
| <html> |
| <head> |
| <meta http-equiv="content-type" content="text/html; charset=UTF-8"> |
| <title>Variations on a theme of window.open</title> |
| </head> |
| <body> |
| <table> |
| |
| <tr> |
| <th>Code</th> |
| <th>Expected result</th> |
| </tr> |
| |
| <tr id="_webScenarioWindowOpenWithBlankTarget"> |
| <td> |
| <input type="button" |
| onclick="window.open('about:blank','_blank')" |
| name="webScenarioWindowOpenWithBlankTarget" |
| id="webScenarioWindowOpenWithBlankTarget" |
| value="webScenarioWindowOpenWithBlankTarget"> |
| </td> |
| <td>about:blank opened in new tab</td> |
| </tr> |
| |
| <tr id="_webScenarioWindowOpenWithEmptyTarget"> |
| <td> |
| <input type="button" |
| onclick="window.open('about:blank','');" |
| name="webScenarioWindowOpenWithEmptyTarget" |
| id="webScenarioWindowOpenWithEmptyTarget" |
| value="webScenarioWindowOpenWithEmptyTarget"> |
| </td> |
| <td>about:blank opened in new tab</td> |
| </tr> |
| |
| <tr id="_webScenarioLocationReplaceInWindowOpenWithEmptyTarget"> |
| <td> |
| <input type="button" |
| onclick="window.open('','').location.replace('about:blank#hash');" |
| name="webScenarioLocationReplaceInWindowOpenWithEmptyTarget" |
| id="webScenarioLocationReplaceInWindowOpenWithEmptyTarget" |
| value="webScenarioLocationReplaceInWindowOpenWithEmptyTarget"> |
| </td> |
| <td>Hash-only location.replace in new empty window</td> |
| </tr> |
| |
| <tr id="_webScenarioWindowOpenRegularLink"> |
| <td> |
| <a href="about:blank" |
| target="_blank" |
| name="webScenarioWindowOpenRegularLink" |
| id="webScenarioWindowOpenRegularLink"> |
| webScenarioWindowOpenRegularLink |
| </a> |
| </td> |
| <td>about:blank opened in new window or tab<br>(via target)</td> |
| </tr> |
| |
| <tr id="_webScenarioWindowOpenRegularLinkMultipleTimes"> |
| <td> |
| <a href="about:blank" |
| target="_blank" |
| name="webScenarioWindowOpenRegularLinkMultipleTimes" |
| id="webScenarioWindowOpenRegularLinkMultipleTimes"> |
| webScenarioWindowOpenRegularLinkMultipleTimes |
| </a> |
| </td> |
| <td>about:blank opened in new window or tab<br>(via target)</td> |
| </tr> |
| |
| <tr id="_webScenarioWindowOpenWithJavaScriptInHref"> |
| <td> |
| <a href="javascript:window.open('about:blank','G','width=640,height=480');" |
| id="webScenarioWindowOpenWithJavaScriptInHref"> |
| webScenarioWindowOpenWithJavaScriptInHref |
| </a> |
| </td> |
| <td>about:blank opened in a new window or tab<br>(via window.open() on a <a href>)</td> |
| </tr> |
| |
| <tr id="_webScenarioWindowOpenWithButtonOnClick"> |
| <td> |
| <button onclick="javascript:window.open('about:blank','G','width=640,height=480');" |
| id="webScenarioWindowOpenWithButtonOnClick"> |
| webScenarioWindowOpenWithButtonOnClick |
| </button> |
| </td> |
| <td>about:blank opened in a new window or tab<br>(via window.open() in a onclick)</td> |
| </tr> |
| |
| <tr id="_webScenarioWindowOpenTabWithAssignmentToHref"> |
| <td> |
| <script> |
| var gotoUrlByHref = function(href) { |
| var newWin = window.open('', 'name', 'width=800,height=600'); |
| newWin.location.href = href; |
| }; |
| </script> |
| <button onclick="javascript:gotoUrlByHref('about:blank');" |
| id="webScenarioWindowOpenTabWithAssignmentToHref"> |
| webScenarioWindowOpenTabWithAssignmentToHref |
| </button> |
| </td> |
| <td>about:blank page opened in new window or tab<br>(via assignment to window.location.href)</td> |
| </tr> |
| |
| <tr id="_webScenarioWindowOpenWithMetaRefresh"> |
| <td> |
| <script> |
| var gotoUrlByMetaRefresh = function(href) { |
| var newWin = window.open('', 'name', 'width=800,height=600'); |
| newWin.document.write('<META HTTP-EQUIV="refresh" content="0; url=' + href + '">'); |
| newWin.document.close(); |
| }; |
| </script> |
| <button onclick="javascript:gotoUrlByMetaRefresh('about:blank');" |
| id="webScenarioWindowOpenWithMetaRefresh"> |
| webScenarioWindowOpenWithMetaRefresh |
| </button> |
| </td> |
| <td>about:blank page opened in new window or tab<br>(via Meta-Refresh in new window)</td> |
| </tr> |
| |
| <tr id="_webScenarioWindowOpenWithPreventDefaultLink"> |
| <td> |
| <a href="http://google.com" |
| onclick="window.open('about:blank','_blank'); event.preventDefault();" |
| name="webScenarioWindowOpenWithPreventDefaultLink" |
| id="webScenarioWindowOpenWithPreventDefaultLink"> |
| webScenarioWindowOpenWithPreventDefaultLink |
| </a> |
| </td> |
| <td>about:blank opened in a new window, with an href and a preventDefault<br></td> |
| </tr> |
| |
| <tr id="_webScenarioWindowOpenAndSetLocation"> |
| <td> |
| <script> |
| var openAndUpdateWindow = function() { |
| var twin = window.open('', '', ''); |
| if (!twin.top) { |
| return; |
| } |
| if (twin.document.title == '') { |
| var target = window.location + "#updated"; |
| twin.location = target; |
| } |
| }; |
| </script> |
| <input type="button" |
| name="button" |
| value="webScenarioWindowOpenAndSetLocation" |
| id="webScenarioWindowOpenAndSetLocation" |
| onclick="openAndUpdateWindow()"> |
| </td> |
| <td>Open a window and set window.location after reading title<br></td> |
| </tr> |
| |
| <tr id="_webScenarioWindowOpenAndCallLocationAssign"> |
| <td> |
| <script> |
| var openAndAssignLocation = function() { |
| var w = window.open(''); |
| var target = window.location + "#assigned"; |
| w.location.assign(target); |
| }; |
| </script> |
| <input type="button" |
| name="button" |
| value="webScenarioWindowOpenAndCallLocationAssign" |
| id="webScenarioWindowOpenAndCallLocationAssign" |
| onclick="openAndAssignLocation()"> |
| </td> |
| <td>Open a window and call location.assign on it<br></td> |
| </tr> |
| |
| <tr id="_webScenarioWindowOpenBlankTargetWithImmediateClose"> |
| <td> |
| <a href="window_close.html" |
| target="_blank" |
| name="webScenarioWindowOpenBlankTargetWithImmediateClose" |
| id="webScenarioWindowOpenBlankTargetWithImmediateClose"> |
| webScenarioWindowOpenBlankTargetWithImmediateClose |
| </a> |
| </td> |
| <td>Open a window with target=_blank that immediately closes itself<br></td> |
| </tr> |
| |
| <tr id="_webScenarioWindowOpenSameURLWithBlankTarget"> |
| <td> |
| <a href="#" |
| target="_blank" |
| name="webScenarioWindowOpenSameURLWithBlankTarget" |
| id="webScenarioWindowOpenSameURLWithBlankTarget"> |
| webScenarioWindowOpenSameURLWithBlankTarget |
| </a> |
| </td> |
| <td>Open same window with target=_blank<br></td> |
| </tr> |
| |
| <tr id="_webScenarioWindowOpenWithDelayedClose"> |
| <td> |
| <a href="window_close.html#2" |
| target="_blank" |
| name="webScenarioWindowOpenWithDelayedClose" |
| id="webScenarioWindowOpenWithDelayedClose"> |
| webScenarioWindowOpenWithDelayedClose |
| </a> |
| </td> |
| <td>Open a window that closes itself after two seconds<br></td> |
| </tr> |
| |
| <tr id="_webScenarioWindowClose"> |
| <td> |
| <input type="button" |
| onclick="window.close()" |
| name="webScenarioWindowClose" |
| id="webScenarioWindowClose" |
| value="webScenarioWindowClose"> |
| </td> |
| <td>Trying to close the current window should fail.<br></td> |
| </tr> |
| |
| <tr id="_webScenarioOpenWindowAndInjectPopup"> |
| <td> |
| <script> |
| var openWindowAndInjectPopup = function() { |
| var url = window.location.href; |
| var w = window.open('', '', ''); |
| var popupScript = |
| "<script>window.open('" + url + "')\<\/script>"; |
| w.document.write(popupScript); |
| }; |
| </script> |
| <input type="button" |
| onclick="openWindowAndInjectPopup()" |
| name="webScenarioOpenWindowAndInjectPopup" |
| id="webScenarioOpenWindowAndInjectPopup" |
| value="webScenarioOpenWindowAndInjectPopup"> |
| </td> |
| <td>Open a window, then inject a window.open call into that window.<br></td> |
| </tr> |
| |
| </table> |
| </body> |
| </html> |