How to force the browser to maximize (like pressing F11) from an NPAPI plugin?

1.7k views Asked by At

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); 
2

There are 2 answers

3
smorgan On BEST ANSWER

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.

1
Grumpy On

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.