0

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;
}
falsarella
  • 12,217
  • 9
  • 69
  • 115
BlackQNX
  • 61
  • 1
  • 8
  • change window.open to window.location = this.href – mkk Dec 16 '11 at 11:25
  • Or don't use jQuery at all, just let the link do its thing. However, I think that the author wants to open a popup window in the background. – Vilx- Dec 16 '11 at 11:30
  • exactly.. I think that the author wants to open a popup window in the background. – BlackQNX Dec 16 '11 at 11:32
  • 1
    I realise that this isn't the answer you're looking for, but I would advise against doing this from an accessibility point of view. Popping up new windows as bad practice, regardless of whether you focus or blur them. If a user wants to open a link in a new window they can do so. Windows are the user's prerogative, not the page's. – graphicdivine Dec 16 '11 at 12:10
  • duplicate of other [StackOverFlow Post](http://stackoverflow.com/questions/2181464/i-need-to-to-open-a-new-window-in-the-background-with-javascript-and-make-sure) – falsarella Dec 16 '11 at 12:34

2 Answers2

0

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.

Vilx-
  • 104,512
  • 87
  • 279
  • 422
0

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();
});
falsarella
  • 12,217
  • 9
  • 69
  • 115
  • unfortunately did not solve the problem ... still takes me to the new window and not in the present. – BlackQNX Dec 16 '11 at 11:51
  • Sorry, @BlackQNX, my mistake, I misunderstood your question... I found a duplicate question: [See here](http://stackoverflow.com/questions/2181464/i-need-to-to-open-a-new-window-in-the-background-with-javascript-and-make-sure). – falsarella Dec 18 '11 at 17:24