関数で動的にスクリプトを読み込んだときのスクリプトの実行順序の確認用。
Created
August 17, 2012 14:00
-
-
Save s-hiroshi/3378918 to your computer and use it in GitHub Desktop.
JavaScript > create script tag dynamic. order of execution.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!DOCTYPE HTML> | |
| <html lang="ja"> | |
| <head> | |
| <meta charset="UTF-8"> | |
| <title>Dynamic script tag</title> | |
| <script> | |
| function appendScript() { | |
| var target = document.createElement('script'); | |
| target.charset = 'utf-8'; | |
| target.src = 'script.js' | |
| document.body.appendChild(target); | |
| document.getElementById('results').innerHTML = 'in appendScript Function'; | |
| } | |
| </script> | |
| </head> | |
| <body> | |
| <div id="results"></div> | |
| <p> | |
| Lorem ipsum dolor sit amet, consectetur adipiscing elit. | |
| </p> | |
| <p> | |
| Ut ac mauris non turpis venenatis fringilla non ut augue. | |
| </p> | |
| <script>appendScript();</script> | |
| </body> | |
| </html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var text = document.getElementById('results').innerHTML; | |
| text += '<br>' + 'in script file.'; | |
| document.getElementById('results').innerHTML = text; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment