简体   繁体   中英

Opening a popup window in the background?

Is there a way in jquery to my browser is not moved by clicking on a link to the new window, so I just stayed in the open window.

Just as it is on the page:

http://www.netvouchercodes.co.uk/expiring-voucher-codes

when you click the Get code & visit, we are on the home page and a window opens in the background.

How do you modify my code to make it work:

Html:

<a href="http://www.yoursite.com/otherLink"  class="yourLink">Click here</a>

Jquery:

$('a.yourLink').click(function(event) {
    $(this).next('.hiddenDiv').show();
    window.open(this.href, '_blank');
    $(this).remove();

    return false;
});

CSS

.hiddenDiv{
    display:none;
}

The popup opens in a foreground window both on Opera and FF. Are you sure you simply haven't changed some browser settings so that your browser opens popups in a background tab? Also, holding down CTRL while clicking on the link will open it in background.

The href does the magic automatically to you, so you don't need to change the location via Javascript. Also, if you handle the hyperlink's click and return it as false, it means for the browser that you didn't clicked at all, so just remove the window.open and the return false , then it should solve your problem:

Html:

<a href="http://www.yoursite.com/otherLink" class="yourLink">Click here</a>

JQuery:

$('a.yourLink').click(function(event) {
    $(this).next('.hiddenDiv').show();
    $(this).remove();
});

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