html - middle click (new tabs) and javascript links -
i in charge of website @ work , have added ajaxy requests make faster , more responsive. has raised issue.
on pages, there index table on left, menu. once have clicked on it, makes request fills rest of page. @ anytime can click on item of index load different page.
before adding javascript, possible middle click (open new tabs) each item of index, allowed have other pages loading while dealing 1 of them. since have changed links ajax requests, execute javascript instead of being real links. opening empty tabs when middle click on them.
is there way combine both functionalities: links firing javascript when left clicked or new tabs when middle clicked? have ugly javascript catches every clicks , deal them accordingly?
thanks.
yes. instead of:
<a href="javascript:code">...</a>
do this:
<a href="/non/ajax/display/page" id="thislink">...</a>
and in js, hook link via it's id ajax call. remember need stop click event bubbling up. frameworks have event killer built in can call (just @ event class).
here's event handling , event-killer in jquery:
$("#thislink").click(function(ev, ob) { alert("thislink clicked"); ev.stoppropagation(); });
of course can lot more clever, while juggling things think it's important stress method so cleaner using onclick
attributes.
Comments
Post a Comment