当 ctrl+ 时,防止当前窗口跟随 onlick/.click() 链接或中键单击
我正在使用 onclick 事件使整个 div 成为可导航链接。这很有效,直到您使用 ctrl+单击或单击鼠标中键在新选项卡中打开目标。我发现确实打开了一个新选项卡,但当前选项卡也是如此。
通过 ctrl+单击此处的其中一个框来了解我的意思: http://mw.modhistory.com/ download-1
我不想因为总是强制进入新选项卡而中断正常浏览的能力...用户应该在此处拥有该选项。但我希望能够在新选项卡中快速打开其中的十几个链接,而不必反复“返回”。
我有一个我认为使用 PreventDefault() 的绝妙主意,但这最终与我的想法相反,并且完全阻止了打开新选项卡的能力(一旦我真正考虑过它是什么,这是有道理的打算这样做。)
有什么想法吗?谢谢!
——弗利格
I'm using an onclick event to make an entire div a navigable link. This works well, until you use ctrl+click or middle-mouse click in order to open the target in a new tab. I find that a new tab does indeed open, but so does the current tab.
See what I mean by ctrl+clicking on one of the boxes here: http://mw.modhistory.com/download-1
I don't want to interrupt the ability to browse normally by always forcing it into a new tab...the user should have the option here. But I'd like to be able to quickly open a dozen of those links in new tabs without having to go "back" repeatedly.
I had what I thought was a brilliant idea to use preventDefault(), but that ended up doing the opposite of what I had in mind and entirely prevented the ability to open a new tab (which makes sense once I really thought about what it is meant to do.)
Any ideas? Thanks!
--Fligg
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我假设您的事件侦听器正在将事件发送到路由/分配函数,或者您希望实现的点击事件并不适合此功能。
无论哪种方式,您都可以执行以下操作:
至于鼠标按钮,它们非常混乱。
您应该可以使用以下任一方法:
或
请记住,过去多年来对确定哪些按钮是哪些按钮的支持确实很糟糕。
如果您有一个可以进行抽象的库,请使用它。
否则,除了向使用较新浏览器的人提供此功能,或编译which和button的先前值之外,它最终会解析浏览器版本,这永远不会很好。
I'm assuming that either your event listener is sending events off to a routing/assigning function, or there aren't a whole lot of click events that you're looking to implement that AREN'T for this feature.
Either way, you can do something like:
As for mouse-buttons, they're pretty messed.
You should be fine using either:
or
Keep in mind that past support for figuring out which buttons were which was REALLY bad over the years.
If you've got a library that does the abstracting, use that.
Otherwise, other than offering this functionality to people with newer browsers, or compiling the previous values of which and button, it ends up at parsing browser versions, which is never, ever good.