Last active
November 20, 2017 00:57
-
-
Save hakobe/5243675 to your computer and use it in GitHub Desktop.
外部 script の読み込みのタイミングによっては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
<html> | |
<!-- | |
"HTML 構文解析器が HTML 文書の末尾まで来たタイミングより後で <script src> で | |
指定されたスクリプト経由で実行される document.write は黙って無視される" by wakabatan | |
see also http://www.whatwg.org/specs/web-apps/current-work/#ignore-destructive-writes-counter | |
$ plackup -p 3005 -e 'use Plack::App::Directory; Plack::App::Directory->new({root=>"."})->to_app' | |
のようにしておためしください | |
--> | |
<body> | |
<div id="target"></div> | |
<script> | |
var scriptElem = document.createElement('script'); | |
scriptElem.src = '/write.js'; | |
var targetElem = document.getElementById('target'); | |
targetElem.appendChild(scriptElem); // このscriptElemで読み込まれるコードは非同期で実行される | |
</script> | |
<h1>h1desu</h1> | |
</body> | |
</html> |
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
console.log('hello1!'); // ログが出力される | |
document.write('<p>hello!!!</p>'); // documentに出力されない | |
console.log('hello2!'); // ログが出力される |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment