Disable Onclick Event If Anchor Href Link Was Executed
I have a table. Each row is a link to some page(for example - google.com) which called by js 'onClick window.open' method:
Solution 1:
I would recommend you to change approach a little. Inline event handlers are never good idea. Consider this code.
HTML:
<tableid="table"><trdata-url="http://google.com"><td>Content</td><td>Content</td><td><ahref="http://jsfiddle.net">JSFiddle</a></td></tr>
...
</table>
JS:
var table = document.getElementById('table');
table.addEventListener('click', function(e) {
var target = e.target;
if (target.tagName == 'A') {
returnfalse;
}
if (target.tagName == 'TD') {
var win = window.open(target.parentNode.getAttribute('data-url'));
win.focus();
}
}, false);
Post a Comment for "Disable Onclick Event If Anchor Href Link Was Executed"