// myjs.js // External Javascript working out things about how it was called, and acting accordingly // RJM Programming - February, 2015 // This type of syntax can be good with prearranged knowledge var myname = document.getElementById("jsid").getAttribute("data-name"); var mysrc = document.getElementById("jsid").getAttribute("src").replace("myjs.js", ""); // This other way can do it too, and we continue on to some generic get parameter processing var thenames = document.URL.split("?"); var thesrc = "", thename = "", ii, iii, xx, zz, ww; var solution = 0, lastoperator = "*", first=1; var listofnumbers=['x0','x1','x2','x3','x4','x5','x6','x7','x8','x9','x_0','x_1','x_2','x_3','x_4','x_5','x_6','x_7','x_8','x_9']; var listofplaces=['Athens','Rome','New York','Moscow','Beijing','Bangkok','Jakarta','Sydney','Pretoria','Cairo']; var listofrivers=['Amazon','Murray','Congo','Rhine','Nile','Danube','Mekong','Mississippi','Ganges','Yangtze']; if (thenames.length > 1) { thename = thenames[0]; thesrc = "?" + document.URL.replace(thename + "?", ""); xx = thesrc.substring(1).split("="); for (ii=1; ii" + "Hope it is good weather in " + decodeURIComponent(listofplaces[iii]).replace(/_/g, " ") + ""; //alert("Hope it is good weather in " + decodeURIComponent(listofplaces[iii]).replace(/_/g, " ")); } } for (iii=0; iii" + "Hope you catch a fish on the " + decodeURIComponent(listofrivers[iii]).replace(/_/g, " ") + " river" + ""; //alert("Hope you catch a fish on the " + decodeURIComponent(listofrivers[iii]).replace(/_/g, " ") + " river"); } } for (iii=0; iii<(listofnumbers.length / 2); iii++) { if (eval("typeof(x" + listofnumbers[iii].replace("x","") + ")") != "undefined" && (eval(decodeURIComponent(ww[ww.length - 1]).replace("x","").replace("_","-").replace(/ /g, "_")) == eval(iii))) { //alert(thesrc + " here at " + iii); if (first == 1) { solution = iii; lastoperator = eval("x" + iii); } else { solution = eval("(" + solution + ") " + lastoperator + " (" + iii + ")"); lastoperator = eval("x" + iii); } first = 0; } else if (eval("typeof(x_" + listofnumbers[iii].replace("x","") + ")") != "undefined" && (eval(decodeURIComponent(ww[ww.length - 1]).replace("x","").replace("_","-").replace(/ /g, "_")) == eval(-iii))) { //alert(thesrc + " here at -" + iii); if (first == 1) { solution = -iii; lastoperator = eval("x_" + iii); } else { solution = eval("(" + solution + ") " + lastoperator + " (-" + iii + ")"); lastoperator = eval("x_" + iii); } first = 0; } } } } if (first == 0) { //alert("Solution is " + solution); document.body.innerHTML=document.body.innerHTML + "

" + "Solution is " + solution + "

"; }