3

Table contain digital values, each cell has each own href.

If I'm apply hrefs like this:

nTd.click(function(e){
   $(this).css("font-weight","bold");
   e.stopPropagation();
   location.href = 'http://google.com';
});

Each click on cell redirect window, I can't open new tab by "ctrl + click".

If I would add in TD something like '<a href="http://google.com"> 123123 </a>', then sorting through digital values would breaks, into lexicographical order.

2 Answers2

4

Make a check to see whether the CTRL key was down when the event occured:

nTd.click(function(e){
   $(this).css("font-weight","bold");
   e.stopPropagation();
    if(e.originalEvent.ctrlKey || e.originalEvent.metaKey){
        window.open("http://www.google.com", "_blank");
    } else {
        location.href = 'http://google.com';   
    }
});

JSFiddle

You won't see the page change in the fiddle, but you'll see the error it produces in the console.

biesior
  • 55,576
  • 10
  • 125
  • 182
George
  • 36,413
  • 9
  • 66
  • 103
0

Going off of the initial question my answer would be: No jquery is needed you can simply change your anchor tag to have the feature target='_blank'. So the full example would be:

<a href="http://google.com" target="_blank"> 123123 </a>

Edit upon more review and another thought: Alternatively you could add this to your function:

window.open('url to open','window name','attribute1,attribute2')

So an actual example to jam in there is:

nTd.click(function(e){
   $(this).css("font-weight","bold");
   e.stopPropagation();
   window.open("http://www.google.com", "_blank");
});

Anchor Tag Reference Javascript open new window reference

Protomancer
  • 140
  • 13
  • this was my knee-jerk answer as well, but i think OP wants a jQuery solution because the clicked element seems to be an `td`, not a link. also, it seems the OP wants the new tab behavior *only* when ctrl is pressed while clicking. – Woodrow Barlow Oct 02 '14 at 18:29
  • Possible, my Engrish is not so good. I'm talking that I can not format data in cells of table. I can't replace digital `123123` with html code like your. – litigious.formalism Oct 02 '14 at 18:30
  • @WoodrowBarlow ah I see more clearly now. Looks like George has got it. – Protomancer Oct 02 '14 at 18:39