I'm working on a simple web form for teachers in my building to generate HTML pages with embedded videos to use locally (our substitutes can't get on the Internet to play videos; this is a workaround).
I'm using a script to take parameters from a form and dynamically build the HTML. I know the server is building the page, not the client, but is there no way for them to save the source?
I tried accessing the content with document.getElementById('main').innerHTML, but because there's no information in the DOM, it returns an error.
<html>
<head>
<script type="text/javascript">
function createNewWindow () {
var userName = document.getElementById('user_name').value
var videoSrc = document.getElementById('video_src').value
var newPage = "<html><head><link rel='stylesheet' type='text/css' media='screen' href='style.css' /><title>"
newPage += userName;
newPage += "</title></head>";
newPage += "<body><div id='main'><div id='content'><div class='video'>";
newPage += "<video controls><source src='" + videoSrc;
newPage += "' type='video/webm'/>";
newPage += "</video></div <!--video-->>"
newPage += "<input type='submit' value='Get Code' onclick='alert(document.getElementById(main).innerHTML);'"
newPage += "</body></html>";
var j = window.open('');
j.document.write(newPage);
j.document.close();
}
</script>
</head>
<body>
<form action="">
<p>
User name: <input type="text" id="user_name">
Video file: <input type="text" id="video_src">
<input type="submit"
value="Create new page"
onclick="createNewWindow();"
>
</p>
</form>
</body>
</html>
I first tried using execCommand to download the content, but running command-level scripts on school computers is blocked, so the solution described in this SO post won't work for me.
I'm stuck on finding a simple way for non-programmers to save the generated page as HTML easily (avoiding Inspect Element, Firebug, etc). Any ideas?
document.getElementById(\'main\').innerHTMLand no, they cannot themselves save the source on your server unless you allow them to send the html to your serverpreelement in the page which the user can easily copy from?window.open()/document.write()approach in the code snippet here will work, and surprisingly none of the answers at stackoverflow.com/questions/3223915/… even suggest using that. (afaict the problem in the OP’s code was just the quoting issue that @mplungjan noted.)