Join the Stack Overflow Community
Stack Overflow is a community of 6.5 million programmers, just like you, helping each other.
Join them; it only takes a minute:
Sign up

I am using simple JavaScript code in my PHP code to display an alert message:

<script type="text/javascript">
    window.alert("Can not Send Messages ")
</script>

When the alert message is displayed, the original page disappears, when I press "OK" button in the message box, the original page will appear again. Is there any way to display the error message and to keep the original page in the back? My other question, is there any way to decorate the message box ^_^ ?

Thanks and Regards for all.

share|improve this question
1  
You can use jQuery for more fancy message boxes. Take a look at here – MadChuckle Mar 11 '12 at 11:25
up vote 7 down vote accepted

alert() blocks until it has been closed. Simple execute it after the document itself has been loaded:

window.onload = function() {
    alert("Cannot send messages");
}

In case you are using something like jQuery you could also use its domready event (it's available without jQuery, too, btw):

$(document).ready(function() {
    alert("Cannot send messages");
});
share|improve this answer

Move that script to the end, after your tag. That way the browser has received enough HTML to construct the page, giving it something to render behind the popup.

share|improve this answer

If you want to decorate system "alert" message you can create your own function and replace default. But you should be sure that there is no libs that uses default alert, or do the follow:

// Preserve link to default alert
var defaultAlert= window.alert;

function myAlert(msg, decorate) {
    if (!decorate)  return defaultAlert(msg);

    // Display decorated alert
    // ... draw beauty div
}

window.alert= myAlert;

And that your alert would not pause execution flow like alert do.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.