简体   繁体   中英

Change name of alert in jscript

Is there a way to change the name of a alert dialog box in jscript, like instead of it saying ("Alert" "Message") can it say something like ("Hello" "Message") this is the script im using:

<a href="#" onclick="alert('message');return false;">Click Here</a>

Thanks :D

If you want to alias alert it would be:

var t = alert;
t('blah');

If you want to change the text of the alert box's title bar, you can not.

The best way to implement an alert with a custom title, would be to implement a custom dialog. You may want to look in to using jQuery UI Dialogs . There are many other implementations of custom Dialog controls. Such as SimpleModal Dialog .

Not as far as I am aware with the default basic Javascript alert() dialog box.

In fact, different browsers will have different title bars on the dialog. Some have "Alert", others have "The page at http://someurl.com says:" and it goes on.

A far prettier, and more customisable option is to consider using something like jQuery UI . It has features like the dialog , which create a nicer, in-page dialog box with customisable buttons, title, and content.

It requires use of the jQuery library, which is a hugely popular Javascript library to greatly ease Javascript development, and plainly, make it more fun .

The short answer is: no.

However, alert is a host method and browsers can chose to implement it however they like. But all browsers currently do not let script modify the standard alert dialogue. You can create your own alert dialogue though using a suitably styled and positioned element.

If you mean function renaming

<script type="text/javascript">
function hello(msg){
    alert(msg);
}
</script>
<a href="#" onclick="hello('message');return false;">Click Here</a>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM