简体   繁体   English

jQuery:请求新标签页/窗口时不打开弹出窗口吗?

[英]jQuery: Do not open popup when new tab/window requested?

I'm trying to make user experience as fine as possible. 我试图使用户体验尽可能的好。 I have two links: to login and to join. 我有两个链接:登录和加入。 When user clicks them, the site darkens and popup (div, not new window of course) appears with appropriate forms. 当用户单击它们时,站点变暗并以适当的形式弹出窗口(div,当然不是新窗口)。

In addition, those links have valid URLs. 此外,这些链接具有有效的URL。 Those forms can be achieved by dedicated URL. 这些形式可以通过专用URL来实现。

My question is, how can I prevent popup from opening when user wants it to open in new tab or window? 我的问题是,当用户希望在新标签页或窗口中打开弹出窗口时,如何防止其打开? Currently, it works great if someone chooses Open in new tab or Open in new window from context menu, but if someone just clicks with cmd , ctrl or shift , the popup opens. 当前,如果有人选择“ Open in new tab Open in new window或从上下文菜单中选择“ Open in new window Open in new tab ,则效果很好,但是如果有人仅使用cmdctrlshift单击,则会打开弹出窗口。 This is not expected, I'd like to allow users to use those shortcuts to have those in separate tab/window. 这是不期望的,我想允许用户使用这些快捷方式将它们放在单独的选项卡/窗口中。

Is there any more fancy way to solve this than listening for cmd , ctrl or shift pressed? 除了侦听cmdctrlShift键之外,还有没有其他更理想的解决方法了?

You can detect shift key and control key in the click event (not sure if that is whay you mean by "listening for .... pessed" because we can check in the click event and not keyboard event. Otherwise, I am sorry for you time) 您可以在click事件中检测到Shift键和Control键(不知道您说的是“侦听.... pessed”是什么意思,因为我们可以检查click事件而不是键盘事件。否则,对不起你时间)

 $(document).click(function(e) { if (e.ctrlKey) { .... // Don't show the div dialog } else if (e.shilfKey) { .... // Don't show the div dialog } else if (e.metaKey) { .... // Don't show the div dialog } else { .... // Show the dialog. } }); 

Sincerely hope this helps. 衷心希望这会有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM