如何防止Firefox在Ctrl选项卡的新选项卡中打开gridview标题排序回发链接 [英] How can I prevent Firefox from opening the gridview header sort postback link in a new tab on Ctrl Click

查看:188
本文介绍了如何防止Firefox在Ctrl选项卡的新选项卡中打开gridview标题排序回发链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使我的gridview控制在ASP.Net做一个多重排序基于如果用户按Ctrl键,当试图点击列名称进行排序。问题是,当我使用Firefox时,如果我点击一个列名称按下Ctrl键,浏览器尝试打开javascript:__ doPostBack('ctl00 $ ContentPla ...链接在一个新的选项卡。除非链接是真正的链接,否则不要这样做。



有一种方法可以防止Firefox在新标签页中打开链接,回复通常?



感谢。

解决方案



在事件处理程序中,检查是否按下了Ctrl(键代码17),如下所示:

  function document_keyDown(e){
var KeyID =(window.event)?event.keyCode:e.keyCode ;
if(KeyID == 17){
ctrlDown = true;
}
}

这里,我将ctrlDown变量设置为true。



对于onKeyUp事件, :

  function document_keyUp(e){
var KeyID =(window.event)? event.keyCode:e.keyCode;
if(KeyID == 17){
ctrlDown = false;然后,在你的列元素的click事件中,
}
}


$ b <您可以检查Ctrl是否已被点击:

  function columnElement_click(){
if(ctrlDown!= undefined && ctrlDown == true)
alert(Ctrl + Click Received);
return false;
}

确保您的列点击处理程序返回false 。否则,浏览器将执行代码,然后导航到链接的href属性中的地址。



希望这有助于。



(另请参见: http:/ /www.geekpedia.com/tutorial138_Get-key-press-event-using-JavaScript.html


I am trying to make my gridview control in ASP.Net do a multi sort based on if the user pressed Ctrl key when trying to sort by clicking on a column name. The problem is that when I am using Firefox, if I click on a column name with Ctrl key pressed, the browser tries to open "javascript:__doPostBack('ctl00$ContentPla..." link in a new tab. IE and Chrome both don't do this unless the link is a real link.

Is there a way I can prevent Firefox from opening the link in a new tab and still cause the page to postback normally?

Thanks.

解决方案

You need to capture the event of the Ctrl key being pushed down, using document.onKeyDown.

In your event handler, check if 'Ctrl' (key code 17) was pressed, as follows:

function document_keyDown(e) {
    var KeyID = (window.event) ? event.keyCode : e.keyCode;
        if (KeyID == 17) { 
            ctrlDown = true;
        }
}

Here, I'm setting a 'ctrlDown' variable to true.

For the onKeyUp event, you can do the exact opposite:

function document_keyUp(e) {
    var KeyID = (window.event) ? event.keyCode : e.keyCode;
    if (KeyID == 17) { 
       ctrlDown = false;
    }
}

Then, in the click event of your column elements, you 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 your column click handler returns false. Otherwise, the browser will execute the code, but then navigate to the address in the link's 'href' attribute.

Hope this helps.

(See also: http://www.geekpedia.com/tutorial138_Get-key-press-event-using-JavaScript.html)

这篇关于如何防止Firefox在Ctrl选项卡的新选项卡中打开gridview标题排序回发链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆