Popup-under hack

Popup-under hack

If you are working on a mobile site, you have a constraint of screen size. What if you are loading a URL from a page using window.open(targetURL,’_blank’);. For your information browser will only focus to the window which is currently opened. So, in this case your window loading targetURL will get focus. And, suppose your boss says to focus to the parent window and not the window with the targetURL. There are a lot of posts available over internet that advises to use below code:-

var myWindow=window.open(targetURL,'_blank');
myWindow.blur();
window.focus();

But wait….due to security reasons modern browsers don’t entertain this feature as they treat the newly opened window in background as malicious. So let me provide you a way for it. All you have to do is to open the currentURL in the new window and in the parent window just refresh the page with targetURL.

var currentURL=window.location.href;
var targetURL='<targetURL>';

window.open(currentURL,'_blank');
document.location.href=targetURL;

And this is not it. With this logic your pages will be rendering in a loop. To stop this just bind a suitable logic to it, may be bind it to a session so that it gets loaded once in a session.

2 comments

  1. Hallo!

    Ich frage mich momentan, welches Diät-Produkt für mich in Frage kommt.
    Ich habe wirklich massenhaft getestet, allerdings nie Erfolge gehabt.
    Auf was sollte man denn vorzugsweise achten? Ich halte nichts von solchen Wundermitteln, die vieles
    versprechen, aber nur wenig erfüllen. Es kann doch auf keinen Fall sein, dass es Millionen von Wundermitteln auf dem Markt gibt, aber kein einziges, das wahrhaftig hilft.

    Über Ideen oder Infos würde ich mich wirklich freuen

    Mit besten Grüßen
    Christin http://onibush2.coppe.ufrj.br/index.php?option=com_k2&view=itemlist&task=user&id=947492

Leave a Reply

Your email address will not be published. Required fields are marked *