Created
March 31, 2017 16:27
-
-
Save xyzzy529/97a79e8f5942dcc4215beb4389e979dc to your computer and use it in GitHub Desktop.
javascript :: custom Alert overriding default native alert in javascript
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<title></title> | |
<link rel=stylesheet href="style.css" /> | |
<script src="jquery.js" type="text/javascript" charset="utf-8"></script> | |
<script> | |
(function(){ | |
var actualAlert = window.alert; | |
window.alert = function(msg){ | |
try{ | |
var title = "Information"; | |
var message = msg; | |
var markup = ['<p class="header">', title, '</p>', | |
'<p class="popcontent">', message, '</p>', | |
'<div class="bbuiButtons">', | |
'<input type="button" value="Ok" id="ok">', | |
].join(''); | |
var popoverlay = document.createElement("div"); | |
popoverlay.setAttribute("id", "popoverlay"); | |
popoverlay.setAttribute("class", "popoverlay"); | |
var bbUiPopup = document.createElement("div"); | |
bbUiPopup.setAttribute("id", "bbUiPopup"); | |
bbUiPopup.setAttribute("class", "bbUiPopup"); | |
bbUiPopup.innerHTML = markup; | |
var bodyTag = document.getElementsByTagName("body")[0]; | |
bodyTag.appendChild(popoverlay); | |
bodyTag.appendChild(bbUiPopup); | |
var okBtn = document.getElementById("ok"); | |
okBtn.onclick = function(){ | |
var overlay = document.getElementById("popoverlay"); | |
var dialogBox = document.getElementById("bbUiPopup"); | |
var bodyElem = document.getElementsByTagName("body")[0]; | |
bodyElem.removeChild(overlay); | |
bodyElem.removeChild(dialogBox); | |
} | |
} catch(err){ | |
return actualAlert(msg); | |
} | |
} | |
})(); | |
</script> | |
</head> | |
<body bgcolor="#69F"> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment