Expanding on the idea of ββMatthew Abbott, it seemed to me that you need an answer that uses simple old Javascript without resorting to any frameworks. Here is a quick and dirty page that emits a div using a simple close button and a message presented in the center:
Rough CSS for the alertBox button and alertClose button
#alertBox{ position:absolute; top:100px; left:100px; border:solid 1px black; background-color: #528CE0; padding: 50px; visibility: hidden; } #alertClose{ position: absolute; right:0; top: 0; background-color: black; border: solid 1px white; color: white; width: 1em; text-align: center; cursor: pointer; }
Then some javascript overrides the built-in alert function and provides a close function to handle the click on alertClose event.
function closeAlertBox(){ alertBox = document.getElementById("alertBox"); alertClose = document.getElementById("alertClose"); alertBox.style.visibility = "hidden"; alertClose.style.visibility = "hidden"; } window.alert = function(msg){ var id = "alertBox", alertBox, closeId = "alertClose", alertClose; alertBox = document.createElement("div"); document.body.appendChild(alertBox); alertBox.id = id; alertBox.innerHTML = msg; alertClose = document.createElement("div"); alertClose.id = closeId; alertClose.innerHTML = "x"; alertBox.appendChild(alertClose); alertBox.style.visibility = "visible"; alertClose.style.visibility = "visible"; alertClose.onclick = closeAlertBox; };
The alert call, as Matthew Abbott suggested, now displays the newly created div and clicking x rejects it, making it invisible.
alert("hello from the dummy alert box.");
To implement, you will need to take a test in the alert function to make sure you are not re-creating the div a million times, and you will need to work around with CSS to match your outline color, etc., but this is a crude form of How to implement your own alert field.
It seems to me that this is too much, and I agree with Matthew that doing this using some kind of dialogue or modal element created using a well-known structure such as jQuery or YUI would be better and strangely simpler in the long run.
DavidHyogo
source share