Open in New Tab

by germandost

HTML

<button class="newwindow" tt="button">Open in New Window</button>
<br/>
<button class="newtab" tt="button">Open in New Tab</button>
<br/>
<br/>
<a href="#" class="newwindow" tt="link">Open in New Window Window</a>

<br/>
<a href="#" class="newtab" tt="link">Open in New Window Tab</a>

<br/>
<div id="output"></div>

JavaScript

var url = "https://www.wikipedia.org/";

$('.newwindow').click(function () {
    $('#output').html($('#output').html() + "<br/> I clicked  new Window " + $(this).attr('tt'));

    var params = "menubar=no,titlebar=no,status=no,toolbar=no,location=no,resizable=no,scrollbars=no,height=500,width=800,top=100, left=250, margin:auto"

    try {
        var newwindow = window.open(url, 'website', params).focus();
        
    } catch (err) {
        $('#output').html($('#output').html() + "<br/> I clicked new Window " + $(this).attr('tt') + " " + err.message);
    }
});

$('.newtab').click(function () {
    $('#output').html($('#output').html() + "<br/> I clicked  new Tab " + $(this).attr('tt'));
    
 try {
        var newwindow = window.open(url, '_blank');
    } catch (err) {
        $('#output').html($('#output').html() + "<br/> I clicked new Tab " + $(this).attr('tt') + " " + err.message);
    }

});