Advertisement
Guest User

Untitled

a guest
Jul 21st, 2015
235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 1.68 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3.     <head>
  4.         <title>Sandbox</title>
  5.         <meta charset="UTF-8">
  6.         <link rel="stylesheet" href="/JSDev/styles.css">
  7.         <script>
  8.             function loadScript(location) {
  9.                 // Check for existing script element and delete it if it exists
  10.                 var js = document.getElementById("sandboxScript");
  11.                 if(js) {
  12.                     document.head.removeChild(js);
  13.                     console.info("---------- Script refreshed ----------");
  14.                 }
  15.                
  16.                 // Create new script element and load a script into it
  17.                 js = document.createElement("script");
  18.                 js.src = location;
  19.                 js.id = "sandboxScript";
  20.                 document.head.appendChild(js);
  21.             }
  22.            
  23.             // Make sure script has loaded and display an alert if it has not
  24.             function runScript() {
  25.                 if(typeof sandbox !== "undefined") {
  26.                     sandbox();
  27.                 } else {
  28.                     window.alert("The script has not been loaded yet!");
  29.                 }
  30.             }
  31.         </script>
  32.     </head>
  33.     <body onload="loadScript('sandbox.js')">
  34.         <h1>Sandbox</h1>
  35.         <button id="refreshButton" onclick="loadScript('sandbox.js')">
  36.             Refresh script
  37.         </button>
  38.         <button id="runButton" onclick="runScript()">
  39.             Run script
  40.         </button>
  41.         <br>
  42.         <button id="refreshRunButton" style="font-weight:bold"
  43.                onclick="loadScript('sandbox.js'); runScript();">
  44.             Refresh and run script
  45.         </button>
  46.     </body>
  47. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement