简体   繁体   English

哪些JavaScript事件可以触发弹出窗口而不会被阻止?

[英]Which javascript events can trigger a popup without being blocked?

I'd like to trigger a popup dialog when a user hits enter in a search box that allows them to give more details before searching. 当用户在搜索框中按下Enter键时,我想触发一个弹出对话框,允许他们在搜索之前提供更多详细信息。 Of course, this works fine when they click on the search button. 当然,当他们单击搜索按钮时,这可以很好地工作。 The popup tends to get blocked when I try to use a keypress handler to trigger the popup when the user hits the enter key. 当我尝试使用按键处理程序在用户按下Enter键时触发弹出窗口时,弹出窗口往往会被阻塞。

Which Javascript events can safely trigger a popup? 哪些Javascript事件可以安全地触发弹出窗口? Is onclick the only one or is there a key handling event (or some other way I haven't thought of)? 是onclick唯一的事件吗?还是有按键处理事件(或我未曾想到的其他某种方式)?

Here's an example: 这是一个例子:

$('input.search').keypress(function(event){
    if (event.keyCode == 13) {
        // trigger popup
    }
});

This does trigger a popup, but popup blockers will catch it most of the time. 这确实会触发弹出窗口,但是弹出窗口阻止程序大多数时候都会捕获它。

Popup blockers today tend to block everything but direct mouse actions. 如今,弹出窗口阻止程序倾向于阻止除直接鼠标操作以外的所有内容。 Perhaps you should consider using ajax to load the preview instead of a popup, then overlaying the ajax result on the page. 也许您应该考虑使用ajax加载预览而不是弹出窗口,然后将ajax结果覆盖在页面上。

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

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