1

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.

rszalski
2,3152 gold badges21 silver badges23 bronze badges
asked Mar 11, 2012 at 11:20
1
  • 1
    You can use jQuery for more fancy message boxes. Take a look at here Commented Mar 11, 2012 at 11:25

3 Answers 3

8

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");
});
answered Mar 11, 2012 at 11:22
Sign up to request clarification or add additional context in comments.

Comments

1

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.

answered Mar 11, 2012 at 11:28

Comments

1

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.

answered Mar 11, 2012 at 11:39

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.