简体   繁体   中英

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. 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.

Which Javascript events can safely trigger a popup? Is onclick the only one or is there a key handling event (or some other way I haven't thought of)?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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