Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html>
- <head>
- <title>Sandbox</title>
- <meta charset="UTF-8">
- <link rel="stylesheet" href="/JSDev/styles.css">
- <script>
- function loadScript(location, runOnLoad) {
- // Check for existing script element and delete it if it exists
- var js = document.getElementById("sandboxScript");
- if(js) {
- document.head.removeChild(js);
- sandbox = undefined;
- console.info("---------- Script refreshed ----------");
- }
- // Create new script element and load a script into it
- js = document.createElement("script");
- document.head.appendChild(js);
- if(runOnLoad)
- js.onload = function() { sandbox(); };
- js.src = location;
- js.id = "sandboxScript";
- }
- // Make sure script has loaded and display an alert if it has not
- function runScript() {
- if(typeof sandbox !== "undefined") {
- sandbox();
- } else {
- window.alert("The script has not been loaded yet!");
- }
- }
- </script>
- </head>
- <body onload="loadScript('sandbox.js')">
- <h1>Sandbox</h1>
- <p><em><a href="/JSDev/">Return to home page</a></em></p>
- <button id="refreshButton" onclick="loadScript('sandbox.js')">
- Refresh script
- </button>
- <button id="runButton" onclick="runScript()">
- Run script
- </button>
- <br>
- <button id="refreshRunButton" style="font-weight:bold"
- onclick="loadScript('sandbox.js', true)">
- Refresh and run script
- </button>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement