Ok, so I am doing html5 canvas / javascript. I play with the idea of making it available to anyone who wants to put the game on their own site, using a small script fragment that links to an external js file.
The entire game is included inside the external js file, all I need to do is find the best way to create a canvas tag using javascript code.
External link js:
<script src="http://host.com/game.js"></script>
Here is one line of canvas code that I need to insert into the document:
<canvas id="canvas" style="display:block;margin:0px auto;" width="600" height="550">Your browser does not support the HTML5 canvas element.</canvas>
1. My first option is to use.
document.write('<canvas id="canvas" style="display:block;margin:0px auto;" width="600" height="550">Your browser does not support the HTML5 canvas element.</canvas>');
However, document.write does not agree with what I understand.
2. My next option is to use.
document.createElement(canvas); document.setAttribute(.....); document.appendChild(....);
However, this option means that I should include a div or some element with an external js link, so I can add a canvas to it.
3. My last known option is to use.
document.getElementById('divWrapper').innerHTML('my canvas code');
However, this option also means that I must include a div with an external js link, so that I can find the div identifier and write inside it via innerHTML.
Last tip: People will be able to copy the js external link and paste it into their own website in the body (it will not be in the head), and if my option requires a div with a script link, this is fine. I am going for the smallest number of characters that a person needs to copy / paste.
Which option would you recommend? Is there any other better way that I haven't mentioned?