Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <html>
- <head>
- <script>
- /* the input type = hidden is necessary or the JS won't be accessible */
- /* script defer tag is also necessary */
- function insertHTMLOnButtonPress() {
- var s = "<html><input type='hidden' id='dummyHidden'/><head><script defer='defer'>function dynamicallyInsertedFunction() { alert('Successfully called - dynamicallyInsertedFunction'); } </sc" + "ript></head><body><input type='text' value='Hello World'/><input type='button' onClick='dynamicallyInsertedFunction();' value='Call Dynamically Inserted Method'/></body></html>";
- /* Clearing out innerHTML is also required to flush the innerHTML so that repeated attempts - i.e new HTML/JS should work */
- document.getElementById('tempBody').innerHTML = '';
- document.getElementById('tempBody').innerHTML = s;
- }
- </script>
- </head>
- <body>
- **********************************<br/>
- <!-- Don't close the div inline, causes some problem and replaces the buttons too -->
- <div id="tempBody"></div>
- **********************************<br/>
- <input type="button" onClick="insertHTMLOnButtonPress();" value="Insert some dynamic html"/>
- <input type="button" onClick="dynamicallyInsertedFunction();" value="Call Dynamically Inserted Method"/>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment