How can I create a custom alert function in Javascript?
You can override the existing alert function, which exists on the window object:
alert
window
window.alert = function (message) { // Do something with message };