Thursday, January 3, 2013

Javascript centered popup window

function popup(url) {
        var width = screen.width - 200;
        var height = screen.height - 150;
        var left = 100;
        var top = 50;
        var params = 'width=' + width + ', height=' + height;
        params += ', top=' + top + ', left=' + left;
        params += ', directories=no';
        params += ', location=no';
        params += ', menubar=no';
        params += ', resizable=no';
        params += ', scrollbars=yes';
        params += ', status=no';
        params += ', toolbar=no';
        newwin = window.open(url, 'NewWindowPopup', params);
        if (window.focus) { newwin.focus() }
        return false;
    }

Call this Function in Code behind
ClientScript.RegisterStartupScript(this.GetType(), "OpenWin", "<script>popup('" + url + "')</script>");

Call this Function in Code behind using Ajax WITH UpdatePanel
ScriptManager.RegisterStartupScript(this, this.GetType(), "OpenWin", "popup('" + url + "')", true);

No comments:

Post a Comment