Design Javascript Popup Windows
Alert, Confirm, Prompt
RJM Programming - March, 2021
alert
("
Hello there
")
confirm
("
Hello there?
")
prompt
("
Hello there?!
","
Hi
")
... versus tailored versions below ...
var alert = function(zwords){ var defwords=''; var vcancel=''; var vok=''; var ansis=location.search.split('val' + pnum + '=')[1] ? decodeURIComponent(decodeURIComponent(location.search.split('val' + pnum + '=')[1].split('&')[0]).replace(/\+/g,' ')) : ''; if (document.URL.indexOf('val' + pnum + '=') == -1) ansis=null; if (document.URL.indexOf('val' + pnum + '=') != -1 && pnum == eval(-1 + xpnum)) { vcancel=location.search.split('Cancel=')[1] ? location.search.split('Cancel=')[1].split('&')[0] : ''; vok=location.search.split('OK=')[1] ? location.search.split('OK=')[1].split('&')[0] : ''; } if (vcancel != '') { pnum++; return null; } else if (vok != '') { pnum++; return ''; } else if (document.getElementById('val' + pnum)) { allowed=false; lastfi=true; document.getElementById('safariform').style.display='block'; while (zwords.indexOf('
') != -1) { zwords=zwords.replace('
',String.fromCharCode(10)); } document.getElementById('prompt').innerHTML=zwords; document.getElementById('val' + pnum).value=defwords; document.getElementById('hval' + pnum).value=encodeURIComponent(defwords); document.getElementById('Cancel').style.display='none'; document.getElementById('bCancel').style.display='none'; document.getElementById('val' + pnum).style.display='none'; document.getElementById('OK').focus(); pnum++; return ansis; } else if (lastfi) { pnum++; lastfi=false; if (ansis == 'null') return null; return ansis; } else { pnum++; if (ansis == 'null') return null; return ansis; } };
var confirm = function(zwords){ //alert('val' + pnum + '=? ' + ' pnum=' + pnum + ' xpnum=' + xpnum + ' ' + document.URL); var defwords='1trueYesOK'; var vcancel=''; var vok=''; var ansis=location.search.split('val' + pnum + '=')[1] ? decodeURIComponent(decodeURIComponent(location.search.split('val' + pnum + '=')[1].split('&')[0]).replace(/\+/g,' ')) : ''; if (document.URL.indexOf('val' + pnum + '=') == -1) ansis=null; if (document.URL.indexOf('val' + pnum + '=') != -1 && pnum == eval(-1 + xpnum)) { vcancel=location.search.split('Cancel=')[1] ? location.search.split('Cancel=')[1].split('&')[0] : ''; vok=location.search.split('OK=')[1] ? location.search.split('OK=')[1].split('&')[0] : ''; } //alert('vok=' + vok); if (vcancel != '') { pnum++; return null; } else if (vok != '') { pnum++; return '1trueYesOK'; } else if (document.getElementById('val' + pnum)) { allowed=false; lastfi=true; document.getElementById('safariform').style.display='block'; while (zwords.indexOf('
') != -1) { zwords=zwords.replace('
',String.fromCharCode(10)); } document.getElementById('prompt').innerHTML=zwords; document.getElementById('val' + pnum).value=defwords; document.getElementById('hval' + pnum).value=encodeURIComponent(defwords); document.getElementById('val' + pnum).style.display='none'; document.getElementById('OK').focus(); pnum++; return ansis; } else if (lastfi) { pnum++; lastfi=false; if (ansis == 'null') return null; return ansis; } else { pnum++; if (ansis == 'null') return null; return ansis; } };
var prompt = function(zwords, defwords){ var vcancel=''; var vok=''; var ansis=location.search.split('val' + pnum + '=')[1] ? decodeURIComponent(decodeURIComponent(location.search.split('val' + pnum + '=')[1].split('&')[0]).replace(/\+/g,' ')) : ''; if (document.URL.indexOf('val' + pnum + '=') == -1) ansis=null; if (document.URL.indexOf('val' + pnum + '=') != -1 && pnum == eval(-1 + xpnum)) { vcancel=location.search.split('Cancel=')[1] ? location.search.split('Cancel=')[1].split('&')[0] : ''; vok=location.search.split('OK=')[1] ? location.search.split('OK=')[1].split('&')[0] : ''; } if (vcancel != '') { pnum++; return null; } else if (vok != '') { pnum++; return ansis; } else if (document.getElementById('val' + pnum)) { allowed=false; lastfi=true; document.getElementById('safariform').style.display='block'; while (zwords.indexOf('
') != -1) { zwords=zwords.replace('
',String.fromCharCode(10)); } document.getElementById('prompt').innerHTML=zwords; document.getElementById('val' + pnum).value=defwords; document.getElementById('hval' + pnum).value=encodeURIComponent(defwords); if (zwords.split(String.fromCharCode(10)).length > eval('0' + document.getElementById('prompt').rows)) { document.getElementById('prompt').rows=zwords.split(String.fromCharCode(10)).length; } else if (zwords.split('
').length > eval('0' + document.getElementById('prompt').rows)) { document.getElementById('prompt').rows=zwords.split('
').length; } document.getElementById('val' + pnum).focus(); pnum++; return ansis; } else if (lastfi) { pnum++; lastfi=false; if (ansis == 'null') return null; return ansis; } else { pnum++; if (ansis == 'null') return null; return ansis; } };