Login | Register | FAQ
Anonymous

Button using JS with functionality of F11 keyboard key

+ Post a reply

4 posts Page 1 of 1


Button using JS with functionality of F11 keyboard key

by cryoffalcon » Thu Apr 26, 2012 11:33 am

Hi,
I want to make a button which if pressed works as if F11 key on keyboard is pressed.
For button html would be like this (I think)

<button type="button" onclick="some function">FullScreen</button>

Now I don't know what function would go in that onclick as I don't have the JS. One more thing that would be nice if the text 'FULLSCREEN' changes to 'NORMAL WINDOW' when the button is pressed, so that the user could realize that they have to press the same button again to get out of fullscreen, it would be like toggle at every click text changes from 'FULLSCREEN' to 'NORMAL WINDOW' and then if pressed again changing to 'FULLSCREEN'.
User avatar

cryoffalcon

  • Posts: 8
  • Joined: Thu Apr 19, 2012 8:08 am

Re: Button using JS with functionality of F11 keyboard key

by XainPro » Thu Apr 26, 2012 1:12 pm

This functionality is seen as a security problem, so no modern browser allows it.
There are lots of code available which does full screen by using java script(alternate methods) use what ever you like i would like to introduce you 2 common methods
1
Code: Select all
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<script language="JavaScript">
function fullScreen() {
var el = document.documentElement
    , rfs = // for newer Webkit and Firefox
           el.requestFullScreen
        || el.webkitRequestFullScreen
        || el.mozRequestFullScreen
        || el.msRequestFullScreen
;
if(typeof rfs!="undefined" && rfs){
  rfs.call(el);
} else if(typeof window.ActiveXObject!="undefined"){
  // for Internet Explorer
  var wscript = new ActiveXObject("WScript.Shell");
  if (wscript!=null) {
     wscript.SendKeys("{F11}");
  }
}

}
// End -->
</script>
</head>
<body><h1 style="text-align: center;">
Open In Full Screen
</h1><div style="text-align: center;"><br>
<a href="javascript:void(0);" onclick="fullScreen('http://google.com');">
Open Full Screen Window
</a>
</div>
</body>
</html>


2nd


Code: Select all
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
<script language="JavaScript">
function fullScreen(theURL) {
window.open(theURL, '', 'fullscreen=yes, scrollbars=auto' );
}
</script>
</head>
<body>
<input type="button" onclick="window.fullScreen('http://www.google.com');
" value="Go Fullscreen" />
</body>
</html>


regards,
XainPro
User avatar

XainPro

  • Posts: 3562
  • Joined: Fri Feb 17, 2012 8:10 pm

Re: Button using JS with functionality of F11 keyboard key

by cryoffalcon » Fri Apr 27, 2012 5:45 am

Thanks for your reply, I guess due to security they are maybe not allowing it as you said, I looked everywhere and didn't find anything.
I like your first method it is almost what I want but it doesn't work in IE8 (haven't tested any other IE versions) in IE it says it got some json error.
User avatar

cryoffalcon

  • Posts: 8
  • Joined: Thu Apr 19, 2012 8:08 am

Re: Button using JS with functionality of F11 keyboard key

by XainPro » Fri Apr 27, 2012 9:57 pm

yah its because of security reasons its not allowed to do things like that in 1999 that was allowed but after that they exclude it.
User avatar

XainPro

  • Posts: 3562
  • Joined: Fri Feb 17, 2012 8:10 pm


+ Post a reply

Page 1 of 1

?>