Start Building Professional
Web Apps Today


 
Categories Question details Back To List
Question  posted by Ben on Feb 02, 2009 21:05
open dhtmlx forum
dhtmlx windows centeronscreen method

When using:
window_object.centerOnScreen();

This works fine in firefox.

But if the page is long, in IE7 the box appears down on the page (requiring scrolling to see it). It looks as if its centering it based on the TOTAL height of the page rather than the screen/viewing area.

Answer posted by Support on Feb 03, 2009 06:50
Here is a demo (file dhtmlxwindows.js is updated).
Attachments (1)
demo.zip18.59 Kb
Answer posted on Feb 03, 2009 07:19
I can't get it to work on our site even with the new JS file sent. 

This is the code we use:
                    var dhtmlx_windows = new dhtmlXWindows();
                    dhtmlx_windows.setImagePath("./images/");
                    dhtmlx_windows.setSkin("clear_silver");
                    var user_id_window_object = dhtmlx_windows.createWindow("user_id_window",50,50,500,300);
                    user_id_window_object.centerOnScreen();
                    user_id_window_object.setText("User ID");
Answer posted on Feb 03, 2009 07:21
The demo sent does not appropriately recreate the bug I am talking about.

The page must be long and have a scroll bar on the browser.
Answer posted by Support on Feb 06, 2009 04:56
All works fine on our side, screenshots are attached.
Attachments (3)
Answer posted on Feb 06, 2009 05:40
That looks like IE6?  We are doing this in IE7
Answer posted on Feb 06, 2009 05:42
Did dhtmlxwindows.js contain a fix for this so would my version have a bug?

I have //v.2.0 build 81107

I am the owner of a commercial license so have the PRO version.


Answer posted by Support on Feb 06, 2009 05:56
IE7: The same result. Here is a screenshot.
Yes you should update your dhtmlxwindows.js file.
Attachments (1)
cen_scr.png60.76 Kb
Answer posted on Feb 06, 2009 06:02
Do you need to send me the PRO version of the file?
Answer posted by Support on Feb 06, 2009 06:24
updated dhtmlxwindow.js for dhtmlxWindows v.2.0 build 81107 PRO, sent by email 
Answer posted on Feb 06, 2009 06:27
I don't know why, but I always have trouble receiving email from you.  I checked all spam lists, etc but it never seems to come.

I have emailed you at support@dhtmlx.com giving multiple alternate email addresses.
Answer posted by Support on Feb 06, 2009 07:03
The file has been just sent to both your email addresses.
Answer posted on Feb 06, 2009 07:28
Still not working, plus the new file added new problems.  Emailed back with a screencast example.
Answer posted on Feb 07, 2009 14:56
I have another issue with this as well.

This happens in both firefox and IE.  If you have a long page that scrolls and you scroll to the bottom, then call centerOnScreen() you will not see the window.  Instead its centered if you scroll back up on the top part of the page.

I sent you a self contained demo via email.
Answer posted on Feb 07, 2009 16:18
See here:
http://www.javascriptkit.com/javatutors/static2.shtml

Near the bottom it talks about doctype.
Answer posted on Feb 07, 2009 17:30
I had to re-do your center function as it was faulty.  It did not take into account the offset.

Here is the new function.

    this._centerWindow = function(win, onScreen) {
        if (win._isMaximized == true) { return; }
        if (win._isParked == true) { return; }
        if (onScreen == true) {
            if(typeof(window.innerWidth) == 'number') {
                //Non-IE
                vpw = window.innerWidth;
                vph = window.innerHeight;
            } else if(document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
                //IE 6+ in 'standards compliant mode'
                vpw = document.documentElement.clientWidth;
                vph = document.documentElement.clientHeight;
            } else if(document.body && (document.body.clientWidth || document.body.clientHeight)) {
                //IE 4 compatible
                vpw = document.body.clientWidth;
                vph = document.body.clientHeight;
            }

            if(typeof(window.pageYOffset) == 'number') {
                //Netscape compliant
                vpw_offset = window.pageXOffset;
                vph_offset = window.pageYOffset;
            } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
                //DOM compliant
                vpw_offset = document.body.scrollLeft;
                vph_offset = document.body.scrollTop;
            } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
                //IE6 standards compliant mode
                vpw_offset = document.documentElement.scrollLeft;
                vph_offset = document.documentElement.scrollTop;
            }
            var vpw = (_isIE?(document.compatMode && document.compatMode != "BackCompat" ? document.documentElement : document.body).offsetWidth:window.innerWidth);
            var vph = (_isIE?(document.compatMode && document.compatMode != "BackCompat" ? document.documentElement : document.body).offsetHeight:window.innerHeight);
            //var vpw_offset = (_isIE?(document.compatMode && document.compatMode != "BackCompat" ? document.documentElement : document.body).offsetWidth:window.pageXOffset);
            //var vph_offset = (_isIE?(document.compatMode && document.compatMode != "BackCompat" ? document.documentElement : document.body).offsetHeight:window.pageYOffset);
        } else {
            //var vpw = (this.vp==document.body?document.body.offsetWidth:(Number(parseInt(this.vp.style.width))&&String(this.vp.style.width).search("%")==-1?parseInt(this.vp.style.width):this.vp.offsetWidth));
            //var vph = (this.vp==document.body?document.body.offsetHeight:(Number(parseInt(this.vp.style.height))&&String(this.vp.style.height).search("%")==-1?parseInt(this.vp.style.height):this.vp.offsetHeight));
            var vpw = (this.vp==document.body?document.body.offsetWidth:(Number(parseInt(this.vp.style.width))&&String(this.vp.style.width).search("%")==-1?parseInt(this.vp.style.width):this.vp.offsetWidth));
            var vph = (this.vp==document.body?document.body.scrollHeight:(Number(parseInt(this.vp.style.height))&&String(this.vp.style.height).search("%")==-1?parseInt(this.vp.style.height):this.vp.offsetHeight));
        }
        //alert(vpw+"x"+vph+"x"+document.body.scrollHeight)
        var newX = (Math.round((vpw/2) - (win.w/2))) + vpw_offset;
        var newY = (Math.round((vph/2) - (win.h/2))) + vph_offset;
        win.x = newX;
        win.y = newY;
        this._fixWindowPositionInViewport(win);
        this._redrawWindow(win);
    }
Answer posted on Feb 07, 2009 17:31
Small correct to code before... these two lines need to be commented out:
var vpw = (_isIE?(document.compatMode && document.compatMode != "BackCompat" ? document.documentElement : document.body).offsetWidth:window.innerWidth);
var vph = (_isIE?(document.compatMode && document.compatMode != "BackCompat" ? document.documentElement : document.body).offsetHeight:window.innerHeight);

Answer posted by Alex on Feb 09, 2009 08:13

Dear Ben,

Could you please provide the sample where the issue can be reproduced  at support@dhtmlx.com

Answer posted on Feb 09, 2009 09:09
I already did?
Answer posted on Feb 09, 2009 09:25
Just to update this for you... here is the final code I am using for the centerOnScreen fix.

    this._centerWindow = function(win, onScreen) {
        if (win._isMaximized == true) { return; }
        if (win._isParked == true) { return; }
       
        vpw_offset = 0;
        vph_offset = 0;
       
        if (onScreen == true) {
            if(typeof(window.innerWidth) == 'number') {
                //Non-IE
                vpw = window.innerWidth;
                vph = window.innerHeight;
            } else if(document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
                //IE 6+ in 'standards compliant mode'
                vpw = document.documentElement.clientWidth;
                vph = document.documentElement.clientHeight;
            } else if(document.body && (document.body.clientWidth || document.body.clientHeight)) {
                //IE 4 compatible
                vpw = document.body.clientWidth;
                vph = document.body.clientHeight;
            }

            if(typeof(window.pageYOffset) == 'number') {
                //Netscape compliant
                vpw_offset = window.pageXOffset;
                vph_offset = window.pageYOffset;
            } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
                //DOM compliant
                vpw_offset = document.body.scrollLeft;
                vph_offset = document.body.scrollTop;
            } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
                //IE6 standards compliant mode
                vpw_offset = document.documentElement.scrollLeft;
                vph_offset = document.documentElement.scrollTop;
            }
            //var vpw = (_isIE?(document.compatMode && document.compatMode != "BackCompat" ? document.documentElement : document.body).offsetWidth:window.innerWidth);
            //var vph = (_isIE?(document.compatMode && document.compatMode != "BackCompat" ? document.documentElement : document.body).offsetHeight:window.innerHeight);
            //var vpw_offset = (_isIE?(document.compatMode && document.compatMode != "BackCompat" ? document.documentElement : document.body).offsetWidth:window.pageXOffset);
            //var vph_offset = (_isIE?(document.compatMode && document.compatMode != "BackCompat" ? document.documentElement : document.body).offsetHeight:window.pageYOffset);
        } else {
            //var vpw = (this.vp==document.body?document.body.offsetWidth:(Number(parseInt(this.vp.style.width))&&String(this.vp.style.width).search("%")==-1?parseInt(this.vp.style.width):this.vp.offsetWidth));
            //var vph = (this.vp==document.body?document.body.offsetHeight:(Number(parseInt(this.vp.style.height))&&String(this.vp.style.height).search("%")==-1?parseInt(this.vp.style.height):this.vp.offsetHeight));
            var vpw = (this.vp==document.body?document.body.offsetWidth:(Number(parseInt(this.vp.style.width))&&String(this.vp.style.width).search("%")==-1?parseInt(this.vp.style.width):this.vp.offsetWidth));
            var vph = (this.vp==document.body?document.body.scrollHeight:(Number(parseInt(this.vp.style.height))&&String(this.vp.style.height).search("%")==-1?parseInt(this.vp.style.height):this.vp.offsetHeight));
        }
        //alert(vpw+"x"+vph+"x"+document.body.scrollHeight)
        var newX = (Math.round((vpw/2) - (win.w/2))) + vpw_offset;
        var newY = (Math.round((vph/2) - (win.h/2))) + vph_offset;
        win.x = newX;
        win.y = newY;
        this._fixWindowPositionInViewport(win);
        this._redrawWindow(win);
    }

Answer posted by Alex (support) on Feb 10, 2009 10:27
The answer was sent by email.
Answer posted on Oct 31, 2009 13:31
How come this was never fixed in the new version?  This still not work work properly.  I still have to replace the code in this file with the code I provided here.
Answer posted by Alex (support) on Nov 02, 2009 05:32

Hello, 

did you post the http://dhtmlx.com/docs/products/kb/index.php?s=normal&q=11733&a=20422 message ?

We have received the email from you. We'll send the answer by email.

Answer posted on Nov 02, 2009 15:52
Yes I posted a few messages concerning this.

It simply does not work.

For instance check out jQuery's dialogue box and how it centers properly and does the modal background properly (in all browsers).  This is how we need your dialogue boxes to work.