There is no need to explain that in most browsers, pressing the F11 button can be displayed as a full -scale page, but at the same time the HTML5 version of an EPA is available to Dolopers, which can allow users to use the site users. Clicking on a specific button to turn the browser page in full -scale mode (what is the API tutorial to learn more about the concept? … It noted that using this IPI can both be full of the entire page and a particular Elman.
Depending on the type of browser we use, the browser relationship methods are also different in this APA. For example, the Firefox method should be called the MozrequestFullscreen method, but in Google Chrome and Safari browsers based on the Webkit rendering engine, we should call the WebkitRequescreen method.
The following block can be considered as a complete and executable example of this IPI. The following code can be in a file with an HTML extension. And save it with a custom name like index.html and run it in the browser:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>HTML5 Fullscreen API</title>
</head>
<body>
<button id="fs-btn">Go Fullscreen</button>
<button id="exit-fs-btn">Exit Fullscreen</button>
</body>
</html>
<script>
function requestFullscreen(element) {
if (element.requestFullscreen) {
element.requestFullscreen();
} else if (element.webkitRequestFullscreen) {
element.webkitRequestFullscreen();
} else if (element.mozRequestFullScreen) {
element.mozRequestFullScreen();
} else if (element.msRequestFullscreen) {
element.msRequestFullscreen();
} else {
console.log('Fullscreen API is not supported.');
}
};
function exitFullscreen() {
if (document.exitFullscreen) {
document.exitFullscreen();
} else if (document.webkitExitFullscreen) {
document.webkitExitFullscreen();
} else if (document.mozCancelFullScreen) {
document.mozCancelFullScreen();
} else if (document.msExitFullscreen) {
document.msExitFullscreen();
} else {
console.log('Fullscreen API is not supported.');
}
};
var fsDocButton = document.getElementById('fs-btn');
var fsExitDocButton = document.getElementById('exit-fs-btn');
fsDocButton.addEventListener('click', function(e) {
e.preventDefault();
requestFullscreen(document.documentElement);
});
fsExitDocButton.addEventListener('click', function(e) {
e.preventDefault();
exitFullscreen();
});
</script>
As can be seen, there are two buttons under the titles of Go Fullscreen and Exit Fullscreen on the screen, which clicks on the first button of the browser screen (full -size) and the second button will remove us from this mode.
Now, in order to better understand the JavaScript code, we are interpreting the line -by -line line. Inside the <scribt> </script> tags we first define a responsive () Requestfulscreen () that provides an input parameter called Element, which will continue to be replaced by the Elmani page that we intend to become full -site. Then we check in the first conditional command to see if the Element parameter is attributed to the standard RequestfulScreen method, if the result was true, this method would be called (in general, the RequestFullscreen method is considered as the main method and standard of communication with this IP. .)
It should be noted that the behavior of different browsers is different from this IPI, so we need to check the specific methods of Chrome/Safari browsers, Firefox and Internet Explorer. In this regard, we have checked in the second conditional order inside this webkitrequescullscreen for Chrome/Safari browsers, in the third condition of the MozrequestFullscreen method for Firefox browser, the fourth condition for the MSREQUESTLSCREEN method and the MSRUSTRALLSCREEN method. Finally, we come to an Else command that if none of the above requirements are met and print a message in the browser console (also keep in mind that the Microsoft AJ browser uses a standard Fullscrenelement method.)
In the following, we have written another function entitled EXITFULLSCREEN () that it has the task to remove the browser from Ful -Sacrine if it is invoked. The standard Fullscreen API method is called ExitfulScreen, but to ensure the function of this function in different browsers, check the proprietary methods of each browser using conditional commands, and if none respond to the browser console We will not print this IPA.
Now, using the following lines, we have identified the buttons based on the ID so that every user clicks on one of them, the corresponding function:
var fsDocButton = document.getElementById('fs-btn');
var fsExitDocButton = document.getElementById('exit-fs-btn');
In the first line we have made a variable called FSDOCButton, which is a completely desirable name, but given the work to be done, it has been tried to choose a name for Bamsami. Using the Document.getEceByid command, which is one of the JavaScript language capabilities, we have ordered to find the FS-BTN ID and attribute it to the FSDOCBUTTON variable. Likewise, in the next line, we have created another variable called Fsexitdocbutton, which has the task to connect to the button responsible for removing the user from the full-scale (GETELETBYID function, which is a built-in function in JavaScript. It has the task of finding an Elmani with a specific ID depending on the input argument we consider.) Now we are going to review a part of the code that will be activated as soon as the user clicks the Go Fullscreen button:
fsDocButton.addEventListener('click', function(e) {
e.preventDefault();
requestFullscreen(document.documentElement);
});
As can be seen, we have attributed another pre -defined function called AddeVentlistener to the FSDOCButton variable, which provides two parameters input. The first parameter is an appointed that we want to implement a specific task that we have used in the example above to have the task of executing the Dolopper’s command whenever the user clicks on the above -mentioned (for example, if we want code. Write to be done after double clicking the Action User, we should use the DBLClick Core.)
The second parameter () is an anonymous function () an anonymous function that we have given an input parameter with a custom name like E (this name derives from the word Event means “event”). As soon as we click on the same as we click on it (in this example, the GO Fullscreen button) is created and then we can select and attribute one of the many methods that JavaScript has to handle events so that in This example has used the preventdefault () method (as the name implies, prevents the default performance of the Elmani we have clicked; in other words, it does not allow the button to do a specific task.)
If we want to explain the performance of the above codes further, as soon as the user clicks on a button with the FS-BTN ID, an anonymous function means the “anonymous function” (Function (E), which is a object output that is a object that is in the object output. The moment a so -called Handler, which can be translated as a “auxiliary tool”, builds E and allocates the object made.
In JavaScript, there are a number of default methods that are for handling events, including Preventdefault (), which when it is called to the object E, the browser performs the default operation on the above -mentioned Elman. It is open (it is necessary to remember that the above can be made with any name. For example, a name (Function (Behzadcustomhandlerwoo!)!
In the following, we have the foundation we built as RequestFullscreen () and we pass document.documenteloment as an input argument (essentially the document.documentelation of the browser). The above explanations are also clear: the following block mechanism:
fsExitDocButton.addEventListener('click', function(e) {
e.preventDefault();
exitFullscreen();
});
If you want to explain very briefly, this block runs from the Exit Fullscreen button as soon as the code clicks and removes the browser page from the fullcker mode.
Conclusion
Although the HTML5 Fullscreen API is a practical tool to allow users of our site that will ultimately lead to a better user experience, let’s not forget that it may change over time how this EPA works may be changed or browser suppliers can be changed. Variously, such as Firefox, Google Chrome, Safari, and so on, change their proprietary mechanism to control it, which is why we need to monitor changes to this IPI documentation when we intend to use it.