Take the 2-minute tour ×

Ok. I'm trying to login to twitter. The window is not opening in this code. The response that gets alerted is not null and is a link to a login screen. Any ideas?

var url = "./twitter_login.php";
var con = createPHPRequest();


var response = "";

con.onreadystatechange = function() {

    if(con.readyState==4 && con.status==200) {

        response = con.responseText;    


share|improve this question
Most browser block window.open if it's not associated with a user event (keyboard, mouse). –  Zeta Aug 5 '12 at 23:33

1 Answer 1

up vote 6 down vote accepted

The standard popup-blocker logic contained in most browsers these days will block any calls to window.open() that are not the direct result of a user action. Code that is triggered by timers or by any asynchronous callback (like your ajax ready function) will be treated as NOT caused directly by user actions and the new popup window will generally be blocked.

You can verify this is what is happening by temporarily changing your browser's popup blocking (turning it off) and see that it then starts working.

Probably what you need to do as a work-around is to create the window upon the user action that started this thread of code and then put the content into the window when you get your ajax response. The browser will probably allow that. I know that's less desirable from a visual perspective, but you can put some temporary content in the window until the ajax response comes in (something like "loading...").

share|improve this answer
Amazingly useful! Create a window on click with window.open, then pass it to your callback in which you'll do mywindow.location = someurl –  lajarre Jan 16 at 11:54

Your Answer


