Advertisement
XT-8147

XT gets drunk and overthinks a problem

Apr 15th, 2017
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 5 1.39 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title>HTML Character Entity Shenanigans</title>
  5. <meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
  6. <style type="text/css">
  7. body {
  8.   font-family: Verdana, sans-serif;
  9.   font-size: 10pt;
  10.   color: #000;
  11.   background-color: #FFF;
  12. }
  13. #output div {
  14.   border-bottom: 1px solid #999;
  15. }
  16. </style>
  17. <script type="text/javascript">
  18. function destroy_die_attack( e ) {
  19.     e.stopPropagation();
  20.     e.preventDefault();
  21. }
  22.  
  23. function check( e ) {
  24.     if( e.keyCode == 13 ) {
  25.         convert();
  26.     }
  27. }
  28.  
  29. function convert() {
  30.     var entity = document.getElementById( 'entity' ).value.replace( /</g, '&lt;' );
  31.     var output = document.getElementById( 'output' );
  32.     var outputElement = document.createElement( 'div' );
  33.     outputElement.innerHTML = entity.replace( /&/g, '&amp;' ).replace( /&amp;lt;/g, '&lt;' ) + ' = ' + entity;
  34.     output.insertBefore( outputElement, output.firstChild );
  35. }
  36.  
  37. window.addEventListener( 'load', function() {
  38.     document.getElementById( 'form' ).addEventListener( 'submit', destroy_die_attack, false );
  39.     document.getElementById( 'convert' ).addEventListener( 'click', convert, false );
  40.     document.getElementById( 'entity' ).addEventListener( 'keyup', check, false );
  41. }, false );
  42. </script>
  43. </head>
  44. <body>
  45. <form id="form">
  46. <input type="text" id="entity" /><input type="button" id="convert" value="Convert" />
  47. <div id="output"></div>
  48. </form>
  49. </body>
  50. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement