Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

`<canvas width="1024" height="768">` Does the browser, the web server or something else automatically add the extra line of HTML?

The following code consists of 2 parts: index.html and game.js.

var game = new Phaser.Game();
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
  <meta charset="utf-8">
  <title></title>
  <script src="https://cdn.jsdelivr.net/npm/phaser@3.55.2/dist/phaser.js"></script>
</head>
<body>
  <script type="text/javascript" src="game.js"></script>
</body>
</html>

The code above doesn’t specify the width and height for the canvas though, when I inspected the page I got, I saw an extra line of HTML

<canvas width="1024" height="768"></canvas>

Who does put it in there? Does the browser, the web server or something else automatically add the extra line of HTML?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

I would put my money on the script you’re requesting in your header:

<script src="https://cdn.jsdelivr.net/npm/phaser@3.55.2/dist/phaser.js"></script>

That contains the code:

/*** 
@const {(number|string)} Phaser.Core.Config#width - The width of the underlying canvas, in pixels.
*/
        this.width = GetValue(config, 'width', 1024);

/*** 
@const {(number|string)} Phaser.Core.Config#height - The height of the underlying canvas, in pixels. 
*/
        this.height = GetValue(config, 'height', 768);

So, to answer your question, it is the browser.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading