This is a useful JavaScript function to create an oAuth popup window which isn’t blocked by web browsers (unless using a popup blocker) and can be monitored with a callback to authenticate through oAuth just like most popular social networks allow.


jQuery Twitter Widget



//Authorization popup window code
$.oauthpopup = function(options)
    options.windowName = options.windowName ||  'ConnectWithOAuth'; // should not include space for IE
    options.windowOptions = options.windowOptions || 'location=0,status=0,width=800,height=400';
    options.callback = options.callback || function(){ window.location.reload(); };
    var that = this;
    that._oauthWindow =, options.windowName, options.windowOptions);
    that._oauthInterval = window.setInterval(function(){
        if (that._oauthWindow.closed) {
    }, 1000);


//create new oAuth popup window and monitor it
    path: urltoopen,
    callback: function()
        //do callback stuff
Sam Deering Sam Deering
Sam Deering is a Front-end Web Developer who specialises in JavaScript & jQuery. Sam is driven and passionate about sharing his knowledge to educate others.

  • sasanka

    hi Sam,

    I am new to JQuery..
    Can you please add full code..

  • Itamar

    Nice post Sam!
    I’m using a very similar code to do OAuth in a popup window,
    but for some reason, Chrome blocks my popup by default.
    Any idea what I’m doing wrong?
    (not using any custom popup blocker)

Related books & courses
Available now on SitePoint Premium

Preview for $1