0

I've inherited a forum which has an unsupported and abandoned mod that makes the entire td element that enclosing any link to sub-forums or threads clickable. It's meant as a usability measure, making it easy to just click on the big table cell that contains the sub-forum or thread you'd like to view.

The problem is that the javascript is not 'middle-click' friendly: using any of the normal keyboard or mouse methods to open links in a new window or tab opens the link in BOTH a new tab AND reloads the current window with the click-on link.

This runs counter to expected behaviour and I'd like to find a solution that allows both the usability feature it introduces AND for standard link-clicking behaviour.

Here's the code that is appended to the containing element:

<td class="info" onclick="window.location.href='http://www.bestcafes.com.au/forum/index.php?board=13.0'" name="b13">

Any suggestions would be most welcome!

kbrookes
  • 13
  • 6

1 Answers1

1

Moving the link to a standard anchor element should do the job:

<td class="info">
    <a href="http://www.bestcafes.com.au/forum/index.php?board=13.0" name="b13">
        …
    </a>
</td>

As suggested in the comments, you also might style them appropriately:

td.info > a { /* only table-cell-links, might need a better selector */
    display: block;
    width:100%; height:100%; /* as long as this doesn't collide with any padding */
    color: inherit; text-decoration: inherit; /* depending on your link style */
}
Bergi
  • 630,263
  • 148
  • 957
  • 1,375
  • Probably with a class or something to make the styling more useful, but this is definitely the way to solve it. To make links act like links, make them links! :-) – T.J. Crowder Dec 18 '12 at 22:31
  • 1
    Don't forget to add style="display:block;" to the Element to fill the whole table cell! – Tyron Dec 18 '12 at 22:32
  • @Tyron: Not `style=...`, use CSS. But yes, it wants that too. – T.J. Crowder Dec 18 '12 at 22:32
  • @T.J.Crowder: You mean `td > a { display: block; }`? Or are you more concerned about the appearance of contents of the link? – Bergi Dec 18 '12 at 22:32
  • @Bergi: You almost certainly **don't** want to make all `a` children of `td` elements `display: block`, hence my suggestion of using a class. I was mostly concerned about overriding the default styling of links, as the default styling would probably lead to a poor UX, but Tyron's point about `display: block` for these specific links is a good one as well. – T.J. Crowder Dec 18 '12 at 22:34
  • Thanks all - great suggestion. My brain was so locked into the 'fixing javascript' approach that I didn't even consider a traditional css approach. – kbrookes Dec 18 '12 at 23:41