Zaloguj | Zarejestruj | FAQ
Anonymous

Button using JS with functionality of F11 keyboard key

+ Odpowiedz

Posty: 4 Strona 1 z 1


Button using JS with functionality of F11 keyboard key

przez cryoffalcon » Cz kwi 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'.
Avatar użytkownika

cryoffalcon

  • Posty: 8
  • Dołączył(a): Cz kwi 19, 2012 8:08 am

Re: Button using JS with functionality of F11 keyboard key

przez XainPro » Cz kwi 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
Kod: Zaznacz cały
<!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


Kod: Zaznacz cały
<!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
Avatar użytkownika

XainPro

  • Posty: 3933
  • Dołączył(a): Pt lut 17, 2012 8:10 pm

Re: Button using JS with functionality of F11 keyboard key

przez cryoffalcon » Pt kwi 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.
Avatar użytkownika

cryoffalcon

  • Posty: 8
  • Dołączył(a): Cz kwi 19, 2012 8:08 am

Re: Button using JS with functionality of F11 keyboard key

przez XainPro » Pt kwi 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.
Avatar użytkownika

XainPro

  • Posty: 3933
  • Dołączył(a): Pt lut 17, 2012 8:10 pm


+ Odpowiedz

Strona 1 z 1