Stiller Eugen
Stiller Eugen

Reputation: 701

Resize window on loading

My Code:

$(document).ready(function() {
    window.resizeTo(1024,800);
});

I'd like to resize the browser window if the site was loaded. Whats wrong?

thanks for help

Upvotes: 2

Views: 1063

Answers (3)

Perfect28
Perfect28

Reputation: 11317

You can't resize a window in javascript. If you can, Imagine a guy running a script like this :

var n = 1 ; 

setInterval(function() {

   if (n++ % 2 == 0) 
   { 
       window.resizeTo(1024,800);
   }
   else 
   {
       window.resizeTo(500,400);
   }

    n = n%2 ; 

}, 20) ;

Upvotes: 2

Chris Fremgen
Chris Fremgen

Reputation: 5358

From cross-browser resize browser window in JavaScript

window.resizeTo( width, height );

The problem you may face is modern day browsers can prevent you in the settings to not be able to resize the window. There is no way around that.

Chrome will not allow it. Won't Fix Bug

IE is based on security zones

So, like Mooseman pointed out, you will have to spawn a new window in order to be able to re-size it.

Upvotes: 0

Mooseman
Mooseman

Reputation: 18891

According to the MDN article for .resizeTo:

  1. You can't resize a window or tab that wasn’t created by window.open.
  2. You can't resize a window or tab when it’s in a window with more than one tab.

Upvotes: 1

Related Questions