controls - How can I prevent Firefox from opening the gridview header sort postback link in a new tab on Ctrl Click -


i trying make gridview control in asp.net multi sort based on if user pressed ctrl key when trying sort clicking on column name. problem when using firefox, if click on column name ctrl key pressed, browser tries open "javascript:__dopostback('ctl00$contentpla..." link in new tab. ie , chrome both don't unless link real link.

is there way can prevent firefox opening link in new tab , still cause page postback normally?

thanks.

you need capture event of ctrl key being pushed down, using document.onkeydown.

in event handler, check if 'ctrl' (key code 17) pressed, follows:

function document_keydown(e) {     var keyid = (window.event) ? event.keycode : e.keycode;         if (keyid == 17) {              ctrldown = true;         } } 

here, i'm setting 'ctrldown' variable true.

for onkeyup event, can exact opposite:

function document_keyup(e) {     var keyid = (window.event) ? event.keycode : e.keycode;     if (keyid == 17) {         ctrldown = false;     } } 

then, in click event of column elements, can check if ctrl has been clicked or not:

function columnelement_click() {     if (ctrldown != undefined && ctrldown == true)         alert("ctrl + click received");     return false; } 

make sure column click handler returns false. otherwise, browser execute code, navigate address in link's 'href' attribute.

hope helps.

(see also: http://www.geekpedia.com/tutorial138_get-key-press-event-using-javascript.html)


Comments

Popular posts from this blog

unicode - Are email addresses allowed to contain non-alphanumeric characters? -

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

c++ - Convert big endian to little endian when reading from a binary file -