Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I make the HTML5 canvas go fullscreen?

I have seen dozens of tutorials on this, and it seems straight forward. All I want is to make my HTML5 canvas element go full-screen (as in total full-screen, taking up the whole monitor).

Here's my HTML:

<p><canvas id="screen" width="800" height="500"
    style="background: #FFFFFF; border: 5px solid black;" role="img">
        Your browser does not support the canvas element.
</canvas></p>

<p><a href="javascript:goFullScreen();">Go Fullscreen</a></p>

Here's my Javascript (in its own .js file):

function goFullScreen(){
    var canvas = document.getElementById("screen");
    if(canvas.requestFullScreen)
        canvas.requestFullScreen();
    else if(canvas.webkitRequestFullScreen)
        canvas.webkitRequestFullScreen();
    else if(canvas.mozRequestFullScreen)
        canvas.mozRequestFullScreen();
}

I tested the function; it gets called and one of the three ifs (namely, since I'm using Firefox, mozRequestFullScreen) gets called. My browser opens it up on every demo that I've tested, but not in my own code.

What's the missing variable? I must have Googled literally every link that mentions this, and still nothing. Thanks.

like image 757
Sefu Avatar asked Apr 20 '13 19:04

Sefu


People also ask

How do you make a canvas cover full screen?

To make canvas fill the whole page, you need to be 100% in width and height of the page.

How do I zoom out in HTML canvas?

Shift-click to zoom out. Mousewheel up/down over the canvas to zoom in to/out from that location. By redrawing the canvas at different scales the strokes remain smooth during zooming.

How do I increase the resolution of a canvas?

In the Properties panel, you can input canvas size width and height at specific values. Use the Units property to change the canvas size units between pixels, inches, or centimeters. Use the Resolution setting to set a print resolution in pixels/inch or pixels/centimeter.

How do I make my Div full screen in Click?

position:absolute You can also use position absolute as well as setting all the viewport sides (top, right, bottom, left) to 0px. This will make the div take the full screen.


1 Answers

Okay, I found the problem. This does not work:

<p><a href="javascript:goFullScreen();">Go Fullscreen</a></p>

This DOES work:

<p><button onclick="goFullScreen();">Go Fullscreen</button></p>

Yeah... 3 hours later.

like image 88
Sefu Avatar answered Sep 21 '22 18:09

Sefu