The web pages below let you explore the complexities of encoding (aka sanitising) and validating data to prevent XSS, the most notorious way for things to go off the rails in modern web-applications.
The central technology here is the mark-up language HTML, but this language involves a range of other technologies including
All the web pages below are totally self-contained: the required JavaScript code is inlined inside the HTML or uses standard APIs provided by any browser, notably the DOM API. Note that the use of inlined JavaScript is considered bad practice as it makes for a poorly maintainable messy mixture of JavaScript code and HTML content. Still, for these demo web pages it has advantages: you can easily make a copy of this web page on your local file system, tinker around with it, and then view - and execute - the result in a browser to see the effect.
The web pages below contain JavaScript code that mimics the behaviour of a web server. More specifically, the pages micic a web template engine that generates a web page using a web template. The pages contain form fields to supply parameters to these templates and buttons to generate a web page by inserting them. The resulting HTML is inserted into the web page using the DOM API so that it is rendered inside the browser.
Two techniques we use are interactively changing a web page and JavaScript template strings:
The second technique, using document.write(), is more realistic as it demonstrates the effect of what would happen if a real web server would send the HTML payload to the browser (as then scripts in the HTML are executed). Still, the first technique, using innerHTML, is useful as it allows you to inspect the HTML that is rendered without execution of scripts.
WARNING: Both techniques are terribly insecure and error-prone ways to interactive modify a web page. Normally you would normally steer clear of using them, but for the demos here they are useful.
In the JavaScript code we make extensive use of JavaScript template strings. These strings, written between back-quotes, can contain both single and double quotes without any escaping. More importantly, string literals support an infix substitution operation, called string interpolation, by including expressions between special brackets ${ }. String literals can span multiple lines, i.e. they can contain newline characters without these having to be escaped, which is useful to keep things readable.