views:

1701

answers:

4

Any idea for this?

Problems encountered: Using screen.availHeight and screen.availWidth as the height and width params in window.open causes the browser size to include the taskbar, and positioning at (0, 0) ignores the possibility of the taskbar being up there.

What I want is to open a new window with the size as if it was "maximized" by the user, i.e. it shouldn't cover the windows taskbar.

(Oh, and no need to remind me that users don't like Javascript interfering with their browser windows, etc. This is for an internal intranet webapp...)

+3  A: 

Does this cause the same problems?

<script type="text/javascript">

    window.moveTo(0,0);
    window.resizeTo(screen.width,screen.height);

</script>
sakabako
This appears to cause a different problem on my machine. The taskbar isn't covered, but part of the window is (i.e. it sits behind the taskbar).Is it possible to open a "proper" maximised window? I.e. you can't drag it from the toolbar or resize it, and it shows the restore down button rather than the maximise one?
Loftx
Try using screen.availWidth and screen.availHeight instead of screen.width and screen.height.As far as I know there is no way to open a properly maximized window, only one that takes up the whole screen.
sakabako
+1  A: 

This might get close to what you want:

window.moveTo(screen.width - screen.availWidth,
              screen.height - screen.availHeight);
window.resizeTo(screen.availWidth + screen.availWidth - screen.width,
                screen.availHeight + screen.availHeight - screen.height);
ars
This doesn't work either - the window sits too low down the screen as the moveTo function takes into account where the taskbar is.
Loftx
A: 

Try this for opening maximised and removing options to lock down users messing with your internal site. You can play around with the restrictions to suit your requirements.

function openFullscreen(url)
{

 // get the height correction for IE and set the window height and width
 var height = screen.availHeight;
 var width = screen.availWidth;

 var fullscreen = (document.all) ? "no" : "yes";
 var resizable = "no";
 var toolbar = "no";
 var status = "no";
 var left = 0;
 var top = 0;

 //set window properties
 props = "toolbar=no" +
 ",fullscreen=" + fullscreen +
 ",status=no" +
 ",resizable=no" +
 ",scrollbars=no" +
 ",menubar=no" +
 ",location=no" + ",";

 dims = "width="+ width +
 ",height="+ height +
 ",left="+ left +
 ",top=" + top;

 var win = window.open("", name, props + dims);
 win.resizeTo(width, height);
 win.location.href = url;
 win.focus();
}
MadMurf
A: 

Taking a quick look at this, it seems

window.moveTo(screen.availLeft, screen.availTop);
window.resizeTo(screen.availWidth, screen.availHeight);

might be the best way to go - I believe this should return exactly the available screen width (It appears to work with on a single monitor if you have multiple monitors).

However it's not a perfect solution - If anyone else has any suggestions on how to open a real maximised window I'd be interested to hear

Loftx