Daily Lucky Numbers:
2
15
19
20
27
45

HTML5 Save Code V3

Started by Chen Zhen, January 09, 2022, 10:58:00 PM

Previous topic - Next topic

Chen Zhen

function saveHTML52score(score, gamename) {
let pathArray = window.location.pathname.split('/');
let newpath = '';
if (pathArray[1] && pathArray[1] != 'arcade' && pathArray[1] != 'games') {
newpath = '/' + pathArray[1];
}
scorepost(window.location.protocol + '//' + window.location.hostname + newpath + '/index.php?act=Arcade&do=newscore', {
gname : gamename,
gscore: score
});
}
function scorepost(href, inputs) {
var gform = document.createElement('form');
gform.method = 'post';
gform.action = href;
gform.target = '_parent';
for (var k in inputs) {
var input = document.createElement('input');
input.setAttribute('name', k);
input.setAttribute('value', inputs[k]);
gform.appendChild(input);
}
document.body.appendChild(gform);
gform.submit();
document.body.removeChild(gform);
}

An example of usage:
var score = parseInt(localStorage.getItem("energizerScore")), gamename = 'energizerCZ';
saveHTML52score(score, gamename);