Skip to content

Instantly share code, notes, and snippets.

@elorz007
Last active April 12, 2021 15:31
Show Gist options
  • Save elorz007/9a1e543b76bdba720745d5600b7a6f44 to your computer and use it in GitHub Desktop.
Save elorz007/9a1e543b76bdba720745d5600b7a6f44 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html>
<head>
<title>Test links</title>
</head>
<body>
<section id="test-links">
<h1>1. Javascript window location</h1>
<p>On chrome it opens in the same tab</p>
<code>window.location = "https://teams.microsoft.com/l/meetup-join/notarealmeeting";</code>
<button onclick="windowLocation()">Open</button>
<h1>2. Javascript window open</h1>
<p>On chrome it opens in a new tab</p>
<code>window.open("https://teams.microsoft.com/l/meetup-join/notarealmeeting")</code>
<button onclick="windowOpen()">Open</button>
<h1>3. Javascript window open (_blank)</h1>
<p>On chrome it opens in a new window</p>
<code>window.open("https://teams.microsoft.com/l/meetup-join/notarealmeeting", "_blank", "toolbar=yes,scrollbars=yes,resizable=yes,top=500,left=500,width=400,height=400");</code>
<button onclick="windowOpenBlank()">Open</button>
<h1>4. HTML &lt;a&gt; tag</h1>
<p>On chrome it opens in the same tab</p>
<code>&lt;a href="https://teams.microsoft.com/l/meetup-join/notarealmeeting"&gt;Open&lt;/a&gt;</code>
<a href="https://teams.microsoft.com/l/meetup-join/notarealmeeting">Open</a>
<h1>5. HTML &lt;a&gt; tag (_blank)</h1>
<p>On chrome it opens in a new tab</p>
<code>&lt;a href="https://teams.microsoft.com/l/meetup-join/notarealmeeting" target="_blank"&gt;Open&lt;/a&gt;</code>
<a href="https://teams.microsoft.com/l/meetup-join/notarealmeeting" target="_blank">Open</a>
<h1>6. HTML &lt;a&gt; tag (_new)</h1>
<p>On chrome it opens in a new tab (unless one with the same name exists)</p>
<code>&lt;a href="https://teams.microsoft.com/l/meetup-join/notarealmeeting" target="_new"&gt;Open&lt;/a&gt;</code>
<a href="https://teams.microsoft.com/l/meetup-join/notarealmeeting" target="_new">Open</a>
<h1>7. Javascript close current tab/window (doesn't work anymore)</h1>
<p>On chrome, Safari and Firefox it does nothing (previously it was closing the current tab, now that is blocked).</p>
<code>window.open("", "_self"); window.close();</code>
<button onclick="closeCurrent()">Open</button>
<h1>8. Javascript window open and close MS Teams (after 3 seconds)</h1>
<p>On chrome it opens in a new window with MS Teams link and closes it after 3 seconds</p>
<code>var win = window.open("https://teams.microsoft.com/l/meetup-join/notarealmeeting", "_blank", ""); setTimeout(function () { win.close();}, 3000);</code>
<button onclick="openAndClose()">Open</button>
<h1>9. Javascript window open and close Google (after 3 seconds)</h1>
<p>On chrome it opens in a new window with google link and closes it after 3 seconds</p>
<code>var win = window.open("https://www.google.com/", "_blank", ""); setTimeout(function () { win.close();}, 3000);</code>
<button onclick="openAndCloseAlt()">Open</button>
<h1>10. Javascript tab open and close MS Teams (after 3 seconds)</h1>
<p>On chrome it opens in a new tab with MS Teams link and closes it after 3 seconds</p>
<code>var win = window.open("https://teams.microsoft.com/l/meetup-join/notarealmeeting"); setTimeout(function () { win.close();}, 3000);</code>
<button onclick="openTabAndClose()">Open</button>
<h1>11. Javascript tab open and close Google (after 3 seconds)</h1>
<p>On chrome it opens in a new tab with google link and closes it after 3 seconds</p>
<code>var win = window.open("https://www.google.com/"); setTimeout(function () { win.close();}, 3000);</code>
<button onclick="openTabAndCloseAlt()">Open</button>
</section>
<script>
function windowLocation() {
window.location = "https://teams.microsoft.com/l/meetup-join/notarealmeeting";
}
function windowOpen() {
window.open("https://teams.microsoft.com/l/meetup-join/notarealmeeting");
}
function windowOpenBlank() {
window.open("https://teams.microsoft.com/l/meetup-join/notarealmeeting", "_blank", "toolbar=yes,scrollbars=yes,resizable=yes,top=500,left=500,width=400,height=400");
}
function closeCurrent() {
// https://stackoverflow.com/a/57197127/1791179
window.open("", "_self");
window.close();
}
function openAndClose() {
// https://stackoverflow.com/a/57197127/1791179
var win = window.open("https://teams.microsoft.com/l/meetup-join/notarealmeeting", "_blank", "");
setTimeout(function () { win.close();}, 3000);
}
function openAndCloseAlt() {
// https://stackoverflow.com/a/57197127/1791179
var win = window.open("https://www.google.com", "_blank", "");
setTimeout(function () { win.close();}, 3000);
}
function openTabAndClose() {
// https://stackoverflow.com/a/57197127/1791179
var win = window.open("https://teams.microsoft.com/l/meetup-join/notarealmeeting");
setTimeout(function () { win.close();}, 3000);
}
function openTabAndCloseAlt() {
// https://stackoverflow.com/a/57197127/1791179
var win = window.open("https://www.google.com");
setTimeout(function () { win.close();}, 3000);
}
</script>
<section>
<br /><br /><br />
<hr />
<p>More info:</p>
<a href="https://confluence.virtual-solution.de/display/SI/WKWebView%3A+Research+the+different+ways+to+open+tabs">https://confluence.virtual-solution.de/display/SI/WKWebView%3A+Research+the+different+ways+to+open+tabs</a>
</section>
<style type="text/css">
code {
display: block;
margin-bottom: 1.5em;
}
#test-links {
padding: 1em;
}
#test-links h1 {
margin-top: 2em;
}
#test-links a,
#test-links button {
font-size: 1.5em;
}
</style>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment