I want emulate the default behavior of the browser like when a link is activated with the middle button of the mouse.
I catch the mousedown to open a new windows.
$('.msk-table-items').mousedown(function (event) {
if (event.which == 2) {
var url = $(this).data('href');
window.open(url, '_blank'); se cambie a la nueva pestaña?
}
});
It works, but changes tab.
I clarify that I want do this on some labels that are not hyperlinks.
Is this possible?
EDIT:
This is an example of a label for this
<tr class="msk-table-items" data-sujetoid="11578" data-href="/Detail/11578">...</tr>
What i am looking for...
I make a selectable list in a table, when one item or many was selected, the web shows options like save in a group, activate, delete, etc...
If the user make a double click in the item, it open, but if the user make a click on it with the middle button, the item open in a new tab.
I want to open the new tab without change the focus to it, the linked solution is not working for me.
function openNewBackgroundTab() {
var a = document.createElement("a");
a.href = window.location.pathname;
var evt = document.createEvent("MouseEvents");
//the tenth parameter of initMouseEvent sets ctrl key
evt.initMouseEvent("click", true, true, window, 0, 0, 0, 0, 0,
true, false, false, false, 0, null);
a.dispatchEvent(evt);
}
function seleccionables() {
$('table.tab-sujetos').selectable({
filter: 'tr',
cancel: '.clickeable',
stop: function () {
var arr = [];
$(".ui-selected", this).each(
function () {
var sujetoId = $(this).data('sujetoid');
arr.push(sujetoId);
}
);
$("." + $(this).data("select")).val(arr);
// show the actions menu
if (arr.length == 1) {
displaySimples();
displayMultiples();
}
else if (arr.length > 1) {
ocultaSimples();
muestraMultiples();
}
else {
ocultaSimples();
ocultaMultiples();
}
// open a element with double click
if ($(".ui-selected", this).length == 1) {
$(".ui-selected", this).first().addClass("clickeable").delay(800).queue(
function (next) {
$(this).removeClass("clickeable");
next();
}
);
}
}
});
$('.msk-table-items').mousedown(function (event) {
if (event.which == 2) {
var is_chrome = navigator.userAgent.toLowerCase().indexOf('chrome') > -1;
if (!is_chrome) {
var url = $(this).data('href');
window.open(url, '_blank');
}
else {
openNewBackgroundTab();
}
}
});
// 2.2 Double click
$(".msk-table-items").dblclick(function () {
var url = $(this).data('href');
window.location = url;
});