开发者

Shift + Click of Linkbutton in Firefox opens new window instead of firing OnClick

I used C# to build a gallery of 开发者_JAVA技巧photos. Users can hold down shift and click to select multiple photos at once. I used the System.Windows.Forms.Control.ModifierKeys property to determine whether shift is being pressed in the OnClick event of a link button, but find that it only works in IE. In Firefox, Shift + Click opens a new window and appears to bypass the button's OnClick event. What is a good solution for getting by this?


You would need to take advantage of javascript to intercept the click and prevent the default action. I would recommend looking at JQuery for doing this.

I actually did something similar in the reverse direction where I use the img replacement methodology for H1 tags to make them linkable and allow them to shift click on the image and launch the new window.

This is half coded free flow so it might take some tweaking but it would be similar to

<script language="javascript" type="text/javascript">
    $(document).ready(function() {
        $('img.selectable').mouseup(function(e) {

            if (e.ctrlKey || (!$.browser.msie && e.button == 1) 
                            || ($.browser.msie && e.button == 4)) {

                //middle mouse button or ctrl+click 
                //(need to lookup values for shift)
                //do something meaningful

            }
            else {
                //normal left click

            }
        })
        .click(function(e) { e.preventDefault(); });
    });                   
</script>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜