开发者

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 b开发者_Python百科rowsers 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...


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:

  • Stack Overflow - To view the silverlight app in fullscreen mode(F11)
  • SitePoint Forums - Trigger F11 using javascript
  • Webmaster World - F11 Fullscreen using Javascript


The window size can be altered by using:

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


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;


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).


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜