最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Change name of alert in jscript - Stack Overflow

programmeradmin1浏览0评论

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

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

Share Improve this question asked Nov 21, 2011 at 1:19 William LewisWilliam Lewis 5361 gold badge8 silver badges26 bronze badges 4
  • Do you mean: hello() instead of alert()? – Jared Farrish Commented Nov 21, 2011 at 1:20
  • It is worth pointing out here that when you call alert in Firefox (5 and up I believe), there is no title on the dialog box! :-) – Ray Toal Commented Nov 21, 2011 at 1:26
  • @JaredFarrish No I mean instead of the dialog box saying Alert: then whatever I said, I want the Alert: to be custom. But it looks like thats impossible. – William Lewis Commented Nov 21, 2011 at 1:30
  • @RayToal Thanks, I was using it in a WebKit browser (android) – William Lewis Commented Nov 21, 2011 at 1:32
Add a ment  | 

5 Answers 5

Reset to default 2

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.

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. 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 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.

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>
发布评论

评论列表(0)

  1. 暂无评论