Mots clés : javascripttabshrefjavascript
92
function openInNewTab(url) { window.open(url, '_blank').focus(); } //or just window.open(url, '_blank').focus();
<div onclick="openInNewTab('www.test.com');">Something To Click On</div>
80
<a class="link">Link</a> <script type="text/javascript"> $("a.link").on("click",function(){ window.open('www.yourdomain.com','_blank'); }); </script>
71
function openInNewTab(href) { Object.assign(document.createElement('a'), { target: '_blank', href: href, }).click(); }
openInNewTab("https://google.com");
60
<!DOCTYPE html> <html> <head> <title>Test</title> </head> <body> <button onclick="window.open('https://stackoverflow.com/q/4907843/456814');"> <code>window.open(url)</code> </button> <button onclick="window.open('https://stackoverflow.com/q/4907843/456814', '_blank');"> <code>window.open(url, '_blank')</code> </button> </body> </html>
<!DOCTYPE html> <html> <head> <title>Test</title> </head> <body> <button onclick="window.open('https://stackoverflow.com/q/4907843/456814', 'test', 'width=400, height=400');"> <code>window.open(url)</code> </button> </body> </html>