سؤال

I am trying to open a link in a new tab/window when a user presses a key.

Here is the function I made for opening a link, it gets called when the user presses the "X" key.

function open_link() {
    window.open($("#active").attr("link"), '_blank');
}

My page consists of a bunch of divs looking like this, and the user sets the active one by navigating up/down with the keys j/k. All this works, but the problem is that there is a popup blocked warning when the "X" key is pressed to open the link.

<div class="read entry" id="active" entryNumber="0" entryId="733" link="http://www.reddit.com/r/buildapc/comments/1aux43/build_help_ordering_soon_final_review/">
هل كانت مفيدة؟

المحلول

I don't think you can disable popup blocker from javascript. If you could, then popup blockers would be quite useless. Have you considered using modal divs instead? E.g. modal dialog from jQueryUI.

نصائح أخرى

That is a problem that you can't avoid, popup blocking is a built in function that all the recent browsers have and getting around a pop-up blocker isn't going to get the user happy.

You can use a jquery/javascript alternative like on-request iframes or modal dialog windows

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top