<!doctype html>
<html>
<head>
<link href='//www.rjmprogramming.com.au/PHP/emboss_h1.css' rel='stylesheet' type='text/css'>
<title>Javascript Writes Javascript ... Numbers Good ... </title>
<script id='myscr' type='text/javascript'>
var ttopalt=location.search.split('window=')[1] ? location.search.split('window=')[1].split('&')[0] : "_self";
var origttopalt=ttopalt;
var ttop=self;
var thisdoc=ttop.document;
var myscr="myscr";
var myscrbit=' function se' + 'ta() { thisdoc.title+=cnt; } ';
var cnt=1;
var done=0;
var myguess=-3;
var lastoff=0;
var lastw=null;
var lastq="";
var prefix="";
var myscore=0;
var myloff="";
var outof=0;
var sio=null;
var extra = location.search.split('extra=')[1] ? location.search.split('extra=')[1].split('&')[0] : '';
eval(decodeURIComponent(extra.replace(/\+/g,' ')));
function assess(loff) {
myloff=loff;
if (navigator.userAgent.match(/Android|BlackBerry|iPhone|iPad|iPod|Opera Mini|IEMobile/i)) {
setTimeout(postassess, 2000);
} else {
postassess();
}
}
function postassess() {
var loff=myloff;
lastoff=eval(loff);
var myf=document.getElementById('myq');
if (myf != null && lastw == null) {
var yyf = (myf.contentWindow || myf.contentDocument);
if (yyf.document) { yyf = yyf.document; }
var parts=yyf.body.innerHTML.split("</");
var preparts=parts[0].split(">");
prefix=preparts[eval(preparts.length - 1)];
}
var smyvalue=prompt(prefix + " Please enter your guess here (as the positive difference between the linked number and the proper answer)", "");
prefix="";
if (smyvalue == null) smyvalue=-2;
if (smyvalue.length == 0) smyvalue=-2;
outof = outof + 1;
if (smyvalue == Math.abs(myguess - lastoff)) {
myscore = myscore + 1;
alert("Congratulations! Score is " + myscore + "/" + outof);
} else {
alert("Bad luck! Score is " + myscore + " /" + outof);
}
myguess = -2;
}
function bpickone() {
var d = new Date();
var n = d.getMilliseconds();
myguess = (n % 100);
return myguess;
}
function amend(thisc) {
var outc=thisc;
if (origttopalt.substring(0,1) != '_') {
var nbits=thisc.split("x");
for (var ibits=1; ibits<nbits.length; ibits++) {
if (nbits[ibits].length > 0) {
outc=outc.replace('x' + nbits[ibits], 'x<a title="Welcome to our Numbers Guess name ... Please enter your guess later (as the positive difference between the linked number and the proper answer to the question you will be asked)" onclick=" if (lastw != null) { lastw.close(); lastw=null; } if (navigator.userAgent.match(/Android|BlackBerry|iPhone|iPad|iPod|Opera Mini|IEMobile/i)) { document.getElementById(' + "'" + 'myq' + "'" + ').src=' + "'" + 'http://www.rjmprogramming.com.au/Games/Battleshipsandcruisers/index2.php?clue=' + "'" + ' + bpickone(); } else { lastw=window.open(' + "'" + 'http://www.rjmprogramming.com.au/Games/Battleshipsandcruisers/index2.php?clue=' + "'" + ' + bpickone(),' + "'" + 'Clue' + "'" + ' + myguess,' + "'" + 'width=600,height=100' + "'" + ',true); } assess(this.innerHTML); " href="#">' + nbits[ibits] + '</a>');
}
}
}
return outc;
}
function involveiframe(ao) {
//alert(ao.innerHTML);
if (ao.innerHTML.indexOf("(involving ") != -1) {
ao.innerHTML=ao.innerHTML.replace("(involving ", "(not involving ");
//alert(ao.innerHTML);
ao.title=ao.title.replace("Involve ", "Do Not Involve ");
document.title=document.title.replace("(not involving ", "(involving ");
document.getElementById('fh1').value=document.getElementById('fh1').value.replace('_self', 'myiframe');
document.getElementById('fh2').value=document.getElementById('fh2').value.replace('_self', 'myiframe');
document.getElementById('fh3').value=document.getElementById('fh3').value.replace('_self', 'myiframe');
if (document.body.innerHTML.indexOf("<iframe") == -1) {
document.body.innerHTML+='<ifr' + 'ame style="display:none;" src="./jswjs_test.html" id="myiframe"></iframe>';
}
} else {
ao.innerHTML=ao.innerHTML.replace("(not involving ", "(involving ");
ao.title=ao.title.replace("Do Not Involve ", "Involve ");
document.title=document.title.replace("(involving ", "(not involving ");
document.getElementById('fh1').value=document.getElementById('fh1').value.replace('myiframe', '_self');
document.getElementById('fh2').value=document.getElementById('fh2').value.replace('myiframe', '_self');
document.getElementById('fh3').value=document.getElementById('fh3').value.replace('myiframe', '_self');
}
}
function iframecheck() {
if (ttopalt != "_self" && extra == '') {
document.getElementById('fh1').value=ttopalt;
document.getElementById('fh2').value=ttopalt;
document.getElementById('fh3').value=ttopalt;
ttop.style.position='absolute';
ttop.style.zindex=4;
ttop.style.top=0;
ttop.style.left=0;
ttop.style.width='100%';
ttop.style.height='100%';
ttop.style.display='block';
}
}
function fixt() {
if (ttopalt != "_parent" && ttopalt.indexOf("_parent") == 0 && extra != '') {
ttop=parent;
document.getElementById('fh1').value=ttopalt; //.replace('_parent','');
document.getElementById('fh2').value=ttopalt; //.replace('_parent','');
document.getElementById('fh3').value=ttopalt; //.replace('_parent','');
ttopalt=ttopalt.replace('_parent','');
}
if (ttopalt != "_self" && extra != '') {
document.getElementById('fh1').value='_parent';
document.getElementById('fh2').value='_parent';
document.getElementById('fh3').value='_parent';
ttop=parent;
}
if (ttopalt != "_self") { // && extra == '') {
//alert(99);
if (extra == '') document.getElementById('fh1').value=ttopalt;
if (extra == '') document.getElementById('fh2').value=ttopalt;
if (extra == '') document.getElementById('fh3').value=ttopalt;
if (extra == '') ttop=document.getElementById(ttopalt);
if (ttop == null) {
if (extra == '') {
if (document.body.innerHTML.indexOf("<iframe") == -1) {
var xfs=thisdoc.getElementsByTagName('form');
for (var xij=0; xij<xfs.length; xij++) {
xfs[xij].target=ttopalt;
}
document.body.innerHTML+='<ifr' + 'ame style="display:none;" src="./jswjs_test.html" id="' + ttopalt + '"></iframe>';
}
ttop=document.getElementById(ttopalt);
if (ttop == null) setTimeout(fixt,1300);
return "";
}
}
thisdoc=ttop.document;
}
//var fs=thisdoc.getElementsByTagName('form');
//for (var ij=0; ij<fs.length; ij++) {
// fs[ij].target=ttopalt;
//}
}
function fthing() {
eval(decodeURIComponent(extra.replace(/\+/g,' ')));
}
function dothing() {
thisdoc.getElementById(myscr).innerHTML+=myscrbit;
}
function sett() {
thisdoc.title+='x';
if (typeof seta !== 'undefined') {
seta();
}
setTimeout(sett, 3000);
}
function presett() {
cnt++;
var myso=thisdoc.getElementById('myscr');
if (myso.innerHTML.indexOf("io" + "n set" + "a(") == -1 && 1 == 2) {
if (1 == 1) {
thisdoc.body.innerHTML += "<script type='text/javascript'> function se" + "ta() { thisdoc.title+='a'; } </s" + "cript>";
} else {
myso.innerHTML=myso.innerHTML.replace("function se" + "tt() {", " function se" + "ta() { thisdoc.title+='a'; } function se" + "tt() {");
//location.reload(true);
}
var xx=thisdoc.URL.split("?");
location.href=xx[0] + "?extra=" + encodeURIComponent("thisdoc.write('<script> function se" + "ta() { thisdoc.title+=cnt; } </scr" + "ipt>'); ") + "#";
}
if (extra == '' || origttopalt.indexOf("_parent") == 0) {
thisdoc.getElementById('sanity').innerHTML=thisdoc.title;
if (origttopalt.indexOf("_parent") == 0) {
document.getElementById('fh1').value=origttopalt.replace("_parent", "");
document.getElementById('fh2').value=origttopalt.replace("_parent", "");
document.getElementById('fh3').value=origttopalt.replace("_parent", "");
} else if (done == 0 && origttopalt == '_self' && extra == '' && document.getElementById('sanity').innerHTML.indexOf(" iframe") == -1) {
done=1;
document.title=document.title.replace(' Javascript .', ' Javascript (not involving iframe) .');
document.getElementById('sanity').innerHTML=document.getElementById('sanity').innerHTML.replace(' Javascript .', ' Javascript <a id="toggle" href="#" onclick="involveiframe(this);" title="Involve Iframe in toggling arrangement">(involving iframe)</a> .');
} else if (origttopalt == '_self' && extra == '' && document.getElementById('sanity').innerHTML.indexOf(" iframe") != -1) {
document.getElementById('sanity').innerHTML=amend(document.title.replace(" (involving iframe) ", " <a id='toggle' href='#' onclick='involveiframe(this);' title='Do Not Involve Iframe in toggling arrangement'>(not involving iframe)</a> ").replace(" (not involving iframe) ", " <a id='toggle' href='#' onclick='involveiframe(this);' title='Involve Iframe in toggling arrangement'>(involving iframe)</a> ").replace(' Numbers Good .',' Numbers Good (' + ttopalt + ') .').replace(' (_self) ', ' ').replace(' (_parent) ', ' '));
}
} else {
document.getElementById('sanity').innerHTML=amend(document.title.replace(" (involving iframe) ", " <a id='toggle' href='#' onclick='involveiframe(this);' title='Do Not Involve Iframe in toggling arrangement'>(not involving iframe)</a> ").replace(" (not involving iframe) ", " <a id='toggle' href='#' onclick='involveiframe(this);' title='Involve Iframe in toggling arrangement'>(involving iframe)</a> ").replace(' Numbers Good .',' Numbers Good (' + ttopalt + ') .').replace(' (_self) ', ' ').replace(' (_parent) ', ' '));
if (document.getElementById('sanity').innerHTML.indexOf(" (") != -1) document.body.style.backgroundColor='orange';
document.body.innerHTML+='<ifr' + 'ame style="display:none;" src="./jswjs_test.html" id="myq"></iframe>';
document.getElementById('fh1').value="_parent" + ttopalt; //.replace('_parent','');
document.getElementById('fh2').value="_parent" + ttopalt; //.replace('_parent','');
document.getElementById('fh3').value="_parent" + ttopalt; //.replace('_parent','');
}
}
function onlcheck() {
if (extra == '' || origttopalt.indexOf("_parent") == 0) {
thisdoc.getElementById('sanity').innerHTML=thisdoc.title;
if (origttopalt.indexOf("_parent") == 0) {
document.getElementById('fh1').value=origttopalt.replace("_parent", "");
document.getElementById('fh2').value=origttopalt.replace("_parent", "");
document.getElementById('fh3').value=origttopalt.replace("_parent", "");
} else if (done == 0 && origttopalt == '_self' && extra == '' && document.getElementById('sanity').innerHTML.indexOf(" iframe") == -1) {
done=1;
document.title=document.title.replace(' Javascript .', ' Javascript (not involving iframe) .');
document.getElementById('sanity').innerHTML=amend(document.getElementById('sanity').innerHTML.replace(' Javascript .', ' Javascript <a id="toggle" href="#" onclick="involveiframe(this);" title="Involve Iframe in toggling arrangement">(involving iframe)</a> .'));
}
} else {
document.getElementById('sanity').innerHTML=amend(document.title.replace(" (not involving iframe) ", " <a id='toggle' href='#' onclick='involveiframe(this);' title='Involve Iframe in toggling arrangement'>(involving iframe)</a> ").replace(' Numbers Good .',' Numbers Good (' + ttopalt + ') .').replace(' (_self) ', ' ').replace(' (_parent) ', ' '));
if (document.getElementById('sanity').innerHTML.indexOf(" (") != -1) {
document.body.style.backgroundColor='orange';
document.body.innerHTML+='<ifr' + 'ame style="display:none;" src="./jswjs_test.html" id="myq"></iframe>';
}
document.getElementById('fh1').value="_parent" + ttopalt; //.replace('_parent','');
document.getElementById('fh2').value="_parent" + ttopalt; //.replace('_parent','');
document.getElementById('fh3').value="_parent" + ttopalt; //.replace('_parent','');
}
if (thisdoc.URL.indexOf("#") != -1) {
//alert(99);
thisdoc.body.innerHTML += "<script type='text/javascript'> function se" + "ta() { thisdoc.title+='a'; } </s" + "cript>";
}
}
</script>
</head>
<body style='background-color:pink;' onload=" fixt(); if (1 == 2) { setTimeout(fthing, 500); } setTimeout(onlcheck,700); sio=setInterval(presett, 2000); setTimeout(sett, 1000); ">
<h1 align='center'>Javascript Writes Javascript - RJM Programming - September, 2015</h1>
<div align='center'>
<br>
<form target='_parent' action='./jswjs_test.html' method='GET'><input type='hidden' id='fh1' name='window' value='_self'></input>
Dynamic Javascript to <a href='#' title=" myscr='myscr' (HTML script tag element in thisdoc.head) and myscrbit=' function se' + 'ta() { thisdoc.title+=cnt; } ' and cnt starts at 0 and increments over time ">add</a>: <input style='width:80%' name='extra' title='Add this Javascript dynamically' value="thisdoc.getElementById(myscr).innerHTML+=myscrbit"></input>
<input onclick='iframecheck();' title='Too hot' style='background-color:red;' type='submit' value='Add Dynamic Javascript (fails because before onload and changing thisdoc.head too early)'></input></form>
<br><br><form target='_parent' action='./jswjs_test.html' method='GET'><input type='hidden' id='fh2' name='window' value='_self'></input>
Dynamic Javascript to <a href='#' title=" function dothing() { thisdoc.getElementById(myscr).innerHTML+=myscrbit; } where myscr='myscr' (HTML script tag element in thisdoc.head) and myscrbit=' function se' + 'ta() { thisdoc.title+=cnt; } ' and cnt starts at 0 and increments over time ">add</a>: <input style='width:80%' name='extra' title='Add this Javascript dynamically' value="setTimeout(dothing,200)"></input>
<input onclick='iframecheck();' title='Too cold' style='background-color:yellow;' type='submit' value='Add Dynamic Javascript (fails because after onload and changing thisdoc.head too late to stop cache taking control)'></input></form>
<br><br><form target='_parent' action='./jswjs_test.html' method='GET'><input type='hidden' id='fh3' name='window' value='_self'></input>
Dynamic Javascript to <a href='#' title=" var extra = location.search.split('extra=')[1] ? location.search.split('extra=')[1].split('&')[0] : ''; eval(decodeURIComponent(extra.replace(/\+/g,' '))); ">add</a>: <input style='width:80%' name='extra' title='Add this Javascript dynamically' value="thisdoc.write('<script> function se' + 'ta() { thisdoc.title+=cnt; } </script>')"></input>
<input onclick='iframecheck();' title='Just right ... aaaaahhhhhh!! (save some porridge for moi)' style='background-color:lightgreen;' type='submit' value='Add Dynamic Javascript (succeeds because before onload and appending new HTML script tag to thisdoc.head)'></input></form>
</div>
<br><br>
<div align='center'>
<span>Document Title Check (numbers good): <p id='sanity'></p></span>
</div>
</body>
</html>