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 is a Front-end Web Developer who specialises in JavaScript & jQuery. Sam is driven and passionate about sharing his knowledge to educate others.

Free Guide:

How to Choose the Right Charting Library for Your Application

How do you make sure that the charting library you choose has everything you need? Sign up to receive this detailed guide from FusionCharts, which explores all the factors you need to consider before making the decision.

  • 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)

Special Offer
Free course!

Git into it! Bonus course Introduction to Git is yours when you take up a free 14 day SitePoint Premium trial.