Skip to main content

js code snippet to open a popup window

By Sam Deering

JavaScript

Share:

Free JavaScript Book!

Write powerful, clean and maintainable JavaScript.

RRP $11.95

Nothing special just some JavaScript code snippet to open a popup window.

W = window,
    D = document;

    //set the window to widgets dimensions
    var winH = 400, //allow for window padding and header
        winW = 400,
        winT = 400,
        winL = 400;

    //set the content
    var windowName = 'Widget', // should not include space for IE
        path = W.location.path,
        windowOptions = 'location=0,status=0,toolbar=0,dependent=1,resizable=1,menubar=0,screenX=' + winL + ',screenY=' + winT + ',width=' + winW + ',height=' + winH,
        that = this;
   
    //note path needs to be in the same domain...

    //open the window
    that._Window = window.open(path, windowName, windowOptions);
    that._Interval = window.setInterval(function () {
        if (that._Window.closed) {
            window.clearInterval(that._Interval);
            //code to run when window is closed

        }
    }, 1000);

Sam Deering has 15+ years of programming and website development experience. He was a website consultant at Console, ABC News, Flight Centre, Sapient Nitro, and the QLD Government and runs a tech blog with over 1 million views per month. Currently, Sam is the Founder of Crypto News, Australia.

New books out now!

Learn how Git works, and how to use it to streamline your workflow!


Google, Netflix and ILM are Python users. Maybe you should too?