Disabling middle click scrolling with javascript

前端 未结 4 2010
礼貌的吻别
礼貌的吻别 2020-11-30 11:21

Background: I am creating a table reminiscent of whenisgood.net, in that it has click-n-drag toggling for table elements. I want to call different types of

4条回答
  •  猫巷女王i
    2020-11-30 12:19

    Currently, my solution is this: (more jquery!)

    $(".togglable").wrap(
      ""
    );
    

    By wrapping it in a link (via jquery wrap), browsers think it's a link and don't scroll on middle click, even if you drag your mouse around. With this setup, and my situation, there are a couple (minor) gotchas.

    Firefox will open a new tab when you middle click, but only if you don't drag. Opera will open a new tab when you middle click, drag or not. That's why I used href='javascript:void(0);' instead of just href='#'--so that the client's browser wouldn't load a whole page, just a blank page with a strange url.

    But this solution works like a charm on Chrome and Safari. It works well with IE8, except that now when I left-click-n-drag, it changes the pointer to a "can't do that" symbol, since it thinks I want to drag the link somewhere. Untested on older versions of IE.

提交回复
热议问题