When the page load the "push_game" is function is called
Code: Select all
function push_game() {
var unixts = document.forms['checkmov']['lastmove'].value;
var Xhand = document.forms['checkmov']['hand'].value;
var Xmove = document.forms['checkmov']['tomove'].value;
var force = 0;
var url = document.location.href;
var xend = url.lastIndexOf("/") + 1;
var base_url = url.substring(0, xend);
thisurl = base_url + 'includes/push_game.php?ts='+unixts+'&h='+Xhand+'&m='+Xmove+'&f='+force;
checkloadfile(thisurl, "js");
thisurl = base_url + 'includes/auto_move.php';
checkloadfile(thisurl, "js");
setTimeout("push_game()", 1000);
}
Code: Select all
document.getElementById('nameofelement').innerHTML = '<table width="1" height="5"><tr><td><img src="images/spacer.gif" width="1" height="5"></td></tr></table>';
Code: Select all
function checkloadfile(filename, filetype){
if (filesadded.indexOf("["+filename+"]")==-1){
loadfile(filename, filetype);
filesadded+="["+filename+"]";
}
else{
replacefile(filename, filename, filetype);
}
}
function loadfile(filename, filetype){
if (filetype=="js"){
var fileref=document.createElement('script') ;
fileref.setAttribute("type","text/javascript") ;
fileref.setAttribute("src", filename) ;
}
else if (filetype=="css"){
var fileref=document.createElement("link");
fileref.setAttribute("rel", "stylesheet") ;
fileref.setAttribute("type", "text/css") ;
fileref.setAttribute("href", filename);
}
if (typeof fileref!="undefined") document.getElementsByTagName("head")[0].appendChild(fileref);
}
function createfile(filename, filetype){
if (filetype=="js"){
var fileref=document.createElement('script') ;
fileref.setAttribute("type","text/javascript") ;
fileref.setAttribute("src", filename) ;
}
return fileref ;
}
function replacefile(oldfilename, newfilename, filetype){
var targetelement=(filetype=="js")? "script" : (filetype=="css")? "link" : "none" ;
var targetattr=(filetype=="js")? "src" : (filetype=="css")? "href" : "none" ;
var allsuspects=document.getElementsByTagName(targetelement);
for (var i=allsuspects.length; i>=0; i--){
if (allsuspects[i] && allsuspects[i].getAttribute(targetattr)!=null && allsuspects[i].getAttribute(targetattr).indexOf(oldfilename)!=-1){
var newelement=createfile(newfilename, filetype);
//DEBUG CODE
$('#loading').text('Trying to reload: '+oldfilename);
//END DEBUG CODE
allsuspects[i].parentNode.replaceChild(newelement, allsuspects[i]);
}
}
}