Skip to content

Instantly share code, notes, and snippets.

@pstjvn
Last active March 17, 2016 18:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pstjvn/dc034f24fa14a079ce92 to your computer and use it in GitHub Desktop.
Save pstjvn/dc034f24fa14a079ce92 to your computer and use it in GitHub Desktop.
Question for l4
<!DOCTYPE html>
<html>
<head>
<title>Test scenario.</title>
</head>
<body>
<script>
var jobs = [], jobn = 0, result = '', i = 1;
var body = "<script>top.result += '3'</scr" +
"ipt><body></body>";
function creationManager() {
if (jobs.length == 0) {
setTimeout(function() {
console.log('>>>', result);
}, 0);
return;
}
result += '1';
jobs[jobn]();
result += '2';
jobn++;
if (jobn >= jobs.length) {
jobs.length = 0;
jobn = 0;
}
creationManager();
}
function writeBody(doc) { doc.write(body); }
function createWindow() {
document.getElementById('c' + i++)
.src = 'javascript:top.writeBody(document)';
};
jobs[jobs.length] = createWindow;
jobs[jobs.length] = createWindow;
window.onload = creationManager;
</script>
<script>document.write("<iframe id='c1' src='about:blank'></iframe><iframe id='c2'></iframe>");</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment