Last active
August 29, 2015 14:27
-
-
Save gindis/33441a8356c049d0718e to your computer and use it in GitHub Desktop.
动态加载js
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="en"> | |
| <head> | |
| <meta charset="UTF-8"> | |
| <title>动态加载js</title> | |
| </head> | |
| <body> | |
| <script> | |
| (function(){ | |
| function loadScript(url, callback) { | |
| var script = document.createElement("script"); | |
| script.type = "text/javascript"; | |
| if (script.readyState) { | |
| script.onreadystatechange = function() { | |
| if (script.readyState == "loaded" || script.readyState == 'complete') { | |
| script.onreadystatechange = null; | |
| callback(); | |
| } | |
| }; | |
| } else { | |
| script.onload = function() { | |
| callback(); | |
| }; | |
| } | |
| script.src = url; | |
| document.getElementsByTagName("head")[0].appendChild(script); | |
| }; | |
| loadScript('http://cdnst.immomo.com/momofes/js/mobile/momo_bridge.2.0.3.min.js', function () { | |
| // callback | |
| }); | |
| })() | |
| </script> | |
| </body> | |
| </html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment