Last active
October 14, 2016 10:42
-
-
Save aloerina01/51e8012367ec04c78c37128d0430b428 to your computer and use it in GitHub Desktop.
document.writeを含むライブラリの動的読込+同期実行
This file contains 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"> | |
<script> | |
(function() { | |
if (!conditions) { // 条件は省略 | |
return; | |
} | |
// 1. create iframe to load a library | |
var iframe = document.createElement('iframe'); | |
var head = document.getElementsByTagName('head')[0]; | |
head.appendChild(iframe); | |
// 2. some functions after loading a library | |
iframe.onload = function() { | |
// 後続処理は省略 | |
} | |
// 3. write sctipt tag in iframe | |
var html = '<body><script src="//scdn.hogehoge.com/library.js"><\/script><\/body>'; | |
var iframeDocument = iframe.contentWindow.document; | |
iframeDocument.open(); | |
iframeDocument.write(html); | |
iframeDocument.close(); | |
})(); | |
</script> | |
</head> | |
<body> | |
<!-- 省略 --> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment