I have small javascript functions, which I think may be useful to others: I use these regularly in my service call events
pre/**
Add a timeout alert function
*
*/
function Alert(msg,duration=3000)
{
var el = document.createElement("div");
el.setAttribute("style", "position:fixed; top:10%; left:10%; border: black 1px solid; background-color:white; color:green; width:80%; text-align: center; z-index: 10;");
el.innerHTML = "
" + msg + "
";
setTimeout(function(){
el.parentNode.removeChild(el);
},duration);
document.body.appendChild(el);
}/**
Echo Error Message for example on service failure
*/
function alertError(msg, duration=3000) {
var el = document.createElement("div");
el.setAttribute("style", "position:fixed; top:10%; left:10%; border: black 1px solid; background-color:white; color:red; width:80%; text-align: center; z-index: 10;");
el.innerHTML = "
" + msg + "
";
setTimeout(function(){
el.parentNode.removeChild(el);
},duration);
document.body.appendChild(el);
}/preusage example:
pre
/**popup message for 4 seconds (default is 3 seconds)
*/
Alert("Service Executed Successfully",4000);
/prepre
/**popup error message for 3 seconds (default)
*/
alertError("Service Execution Failed");
/pre