0

I have a scriptable NPAPI browser plugin.
I would like to expose a method to javascript "MaximizeBrowser",
that will cause the browser window to maximize (as if the user pressed F11 in the broswer).
Is there a way to achieve that?

The selected answer works (at least on Windows)!
Here is my code, in case someone needs:

// simulate F11 keyboard key press
keybd_event(VK_F11,MapVirtualKey(VK_F11,0),0,0); 
keybd_event(VK_F11,MapVirtualKey(VK_F11,0),KEYEVENTF_KEYUP,0); 
Supun Wijerathne
  • 11,964
  • 10
  • 61
  • 87
Gil
  • 395
  • 4
  • 19

2 Answers2

2

There's certainly no supported way using the NPAPI APIs, but depending on what OS you are targeting you could try using OS-level calls to simulate a keyboard event matching the browser's full-screen mode. That will of course be fragile since it depends on every browser you are targeting a) having a full screen mode, and b) never changing the shortcut.

If your goal is to have your plugin content be full-screen, perhaps you should instead consider opening a full-screen window from your plugin, which is how other NPAPI plugins go full-screen.

smorgan
  • 20,228
  • 3
  • 47
  • 55
  • yeah... this is pretty much your only option – taxilian Feb 28 '11 at 16:23
  • 1
    Good idea, I will simulate F11 key press. Good enough for now. – Gil Feb 28 '11 at 18:42
  • I do it as a demo-hack, instead of opening "real" full screen from my windowless plugin. I have to do it in order to display semi-transparent content (e.g. flash) from the browser beneath, on top of the plugin's content. A bit complicated... Thanks a lot. – Gil Feb 28 '11 at 18:46
1

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.

Grumpy
  • 2,140
  • 1
  • 25
  • 38