aaandre
aaandre

Reputation: 2512

Javascript: Automatically maximize browser window and switch to full screen mode?

I am working on a Flash app that is 900x700 pixels. When viewed in misc. browsers at 1024x768, the browser chrome causes robs too much of the vertical space and the app appears in a window with a vertical scrollbar. Unacceptable.

The flash app will be launched via a link emailed to the viewers.

I'd like to avoid resizing the flash app and am wondering if there's a way to do the following via javascript, with no clicks involved:

  1. maximize the current browser window
  2. remove current window address bar and tabs / switch browser to full screen view (equivalent to pressing F11).

An alternative would be to resize the flash app vertically to match the browser canvas height to avoid scrolling. This may cause the app to become unreadable, so not the best approach in my case.

Thank you!

UPDATE: Seems that browser resizing and autoswitch to full screen won't work and neither will the flash app auto resize. What is the best approach then? And, some users may have browsers with toolbars or open a small browser window.

The only idea I have is to use javascript and display a message to users with small browser windows to pres F11 manually. The audience is executes and some may not even know what an F11 means...

Upvotes: 2

Views: 11544

Answers (5)

Simon Lieschke
Simon Lieschke

Reputation: 13333

Chrome 15, Firefox 10, and Safari 5.1 now provide APIs to programmatically trigger fullscreen mode. Fullscreen mode triggered this way provide events to detect fullscreen changes and CSS pseudo-classes for styling fullscreen elements. These APIs may present you with a more acceptable solution for those browsers.

See this hacks.mozilla.org blog post for details.

Upvotes: 1

sberry
sberry

Reputation: 132138

To answer the question in the comment you made to your own post. Yes. You can have a button whose click handler does this

stage.displayState = StageDisplayState.FULL_SCREEN;

Upvotes: 1

The window size can be altered by using:

window.moveTo(0, 0);
window.resizeTo(screen.availWidth, screen.availHeight);

Upvotes: 2

Gabriel McAdams
Gabriel McAdams

Reputation: 58293

You can use JavaScript to open a new window (using window.open) and control the window that is opened (no address bar, etc). You can also control the size of the window (you can't maximize it, but you can get the users screen size, and set the window that same size).

Upvotes: 1

Daniel Vassallo
Daniel Vassallo

Reputation: 344521

There is no way to maximize the browser window to full screen with JavaScript. While this is unfortunate for your genuine requirement, it is considered a security restriction.

Sources:

Upvotes: 4

Related Questions