Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cross-browser resize browser window in JavaScript

Tags:

I would like to be able to resize the browser window with JavaScript. I don't want to use jQuery, and the smaller the code the better, but it has to work in all of the major browsers including Chrome.

Any solutions?

Thanks for the help!

P.S. The tags that this question was tagged with should be combined but I don't know how.

browser -----------same as--> webbrowser

cross-browser----same as--> browser compatibility

like image 601
Web_Designer Avatar asked Sep 17 '11 02:09

Web_Designer


People also ask

How do you resize browser window?

* Press Alt+Space to bring up the window menu, press S to choose the Size option, use the arrow keys to resize the window, and lastly Enter to confirm. * Click the Maximize button in the top right corner of the window. * Click the title bar and drag the window to the left, top, or right edge of the desktop.

How do I resize a browser window in HTML?

The resizeTo() method is used to resizes a window to the specified width and height. Parameter Values: width: Sets the width of the window, in pixels. height: Sets the height of the window, in pixels.

How do I stop a browser window from resizing after a specific size?

You can not control the size of the window. You can use CSS to set min-width and min-height properties to ensure your page layout stays sane. using 'window. open' I can open a page with a fixed height width.

What is use of $( window resize ();?

Definition and Usage The resize event occurs when the browser window changes size. The resize() method triggers the resize event, or attaches a function to run when a resize event occurs.


2 Answers

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

like image 168
epascarello Avatar answered Nov 18 '22 05:11

epascarello


The fact is that Chrome, Firefox and newer IEs doesn't allow resize of tabbed windows and windows not opened by window.open() (Chrome at least).

But for popups it's doable for the most part, unless the security setting in the browser blocks that functionality. However using window.resizeTo() is complicated. Use window.resizeBy() instead.

Chrome has a bug getting the size of a popup window to soon so you have to work around that.

if(navigator.userAgent.toLowerCase().indexOf('chrome') > -1)     var t = setTimeout("resize()", 200); else     resize();  function resize() {     var innerWidth = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;     var innerHeight = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight;     var targetWidth = 800;     var targetHeight = 600;     window.resizeBy(targetWidth-innerWidth, targetHeight-innerHeight); } 
like image 35
tivolimeister Avatar answered Nov 18 '22 05:11

tivolimeister