I'm making a php/html app which show some data in a table, when the user clicks in the row (<tr>
) jquery open that record.
This is the code:
$.fn.linkRow = function(element) {
thisRow = this.find('tbody tr');
thisRow.on('click', function() {
hrefLocation = $(this).find('td.link:first a').attr('href');
if (hrefLocation) {
window.location.href = hrefLocation;
};
}).addClass((thisRow.has('td.link')) ? 'pointer' : '');
return this;
};
The fact is: The user can't open a record in a new tab. The only way is copy&paste the href
... And my users won't do that.
If make some research about the event fired by the scroll button and how to open a new tab, the later is almost impossible, so... Does anyone can figure a way?
EDIT: I mean the mouse-wheel... Normally this open a link in a new tab.
PS: I have to use tables, In some point I will make a css-based table layout for that (no javascript needed), but I can't do it in this version of the software.
Thanks!
This is the final code:
$.fn.linkRow = function(element) { thisRow = this.find('tbody tr'); thisRow.not('a').on('mouseup', function(e) { hrefLocation = $(this).find('td.link:first a:first').attr('href'); if ( hrefLocation ) { if (e.which == 2) { window.open(hrefLocation); } else{ window.location.href = hrefLocation; } }; }).addClass( ( thisRow.has('td.link') ) ? 'pointer' : '' ); return this; };
BUT... The mouse-wheel click does not work for what I intend:
If you click a link (a
tag) > open a new tab
If you click a no link (any other tag) > it will scroll based on your mouse position. if you move your mouse up, it scrolls up and so
So... I works but I definitively need to make a no-javascript solution.