如何编辑 JavaScript 警报框标题?

发布于 2024-08-14 12:28:13 字数 221 浏览 5 评论 0原文

我在 C# .NET 页面中使用以下代码生成 JavaScript 警报:

Response.Write("<script language=JavaScript> alert('Hi select a valid date'); </script>");

它显示一个标题为“来自网页的消息”的警报框。

标题可以修改吗?

I'm generating a JavaScript alert with following code in C# .NET page:

Response.Write("<script language=JavaScript> alert('Hi select a valid date'); </script>");

It displays an alert box with the heading title as "Message from webpage".

Is it possible to modify the title?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(10

羁〃客ぐ 2024-08-21 12:28:13

不,你不能。

这是一项安全/反网络钓鱼功能。

No, you can't.

It's a security/anti-phishing feature.

哀由 2024-08-21 12:28:13

不,这是不可能的。您可以使用自定义 JavaScript 警报框。

使用 jQuery 找到了一个不错的

jQuery 警报对话框(警报、确认和提示替换)< /a>

No, it is not possible. You can use a custom javascript alert box.

Found a nice one using jQuery

jQuery Alert Dialogs (Alert, Confirm, & Prompt Replacements)

独守阴晴ぅ圆缺 2024-08-21 12:28:13

您可以在 IE 中执行此操作:(

<script language="VBScript">
Sub myAlert(title, content)
      MsgBox content, 0, title
End Sub
</script>

<script type="text/javascript">
myAlert("My custom title", "Some content");
</script>

尽管我真的希望您不能这样做。)

You can do this in IE:

<script language="VBScript">
Sub myAlert(title, content)
      MsgBox content, 0, title
End Sub
</script>

<script type="text/javascript">
myAlert("My custom title", "Some content");
</script>

(Although, I really wish you couldn't.)

檐上三寸雪 2024-08-21 12:28:13

我找到了这个 Sweetalert 用于自定义标题框 JavaScript。

例如

swal({
  title: "Are you sure?",
  text: "You will not be able to recover this imaginary file!",
  type: "warning",
  showCancelButton: true,
  confirmButtonColor: "#DD6B55",
  confirmButtonText: "Yes, delete it!",
  closeOnConfirm: false
},
function(){
  swal("Deleted!", "Your imaginary file has been deleted.", "success");
});

I Found this Sweetalert for customize header box javascript.

For example

swal({
  title: "Are you sure?",
  text: "You will not be able to recover this imaginary file!",
  type: "warning",
  showCancelButton: true,
  confirmButtonColor: "#DD6B55",
  confirmButtonText: "Yes, delete it!",
  closeOnConfirm: false
},
function(){
  swal("Deleted!", "Your imaginary file has been deleted.", "success");
});
梦里泪两行 2024-08-21 12:28:13

重写 javascript window.alert() 函数。

window.alert = function(title, message){
    var myElementToShow = document.getElementById("someElementId");
    myElementToShow.innerHTML = title + "</br>" + message; 
}

这样您就可以创建自己的 alert() 函数。创建一个新的“酷”外观对话框(来自一些 div 元素)。

在 chrome 和 webkit 中测试过,不确定其他的。

Override the javascript window.alert() function.

window.alert = function(title, message){
    var myElementToShow = document.getElementById("someElementId");
    myElementToShow.innerHTML = title + "</br>" + message; 
}

With this you can create your own alert() function. Create a new 'cool' looking dialog (from some div elements).

Tested working in chrome and webkit, not sure of others.

梦在夏天 2024-08-21 12:28:13

根据你提出的问题来回答问题。

这实际上非常简单(至少在 Internet Explorer 中),我只用了 17.5 秒就完成了。

如果您使用cxfx提供的自定义脚本:(将其放入您的apsx文件中)

<script language="VBScript">
Sub myAlert(title, content)
MsgBox content, 0, title 
End Sub 
</script>

然后您可以像调用常规警报一样调用它。只需将您的代码修改为以下内容即可。

Response.Write("<script language=JavaScript> myAlert('Message Header Here','Hi select a valid date'); </script>");

希望对您或其他人有帮助!

To answer the questions in terms of how you asked it.

This is actually REALLY easy (in Internet Explorer, at least), i did it in like 17.5 seconds.

If you use the custom script that cxfx provided: (place it in your apsx file)

<script language="VBScript">
Sub myAlert(title, content)
MsgBox content, 0, title 
End Sub 
</script>

You can then call it just like you called the regular alert. Just modify your code to the following.

Response.Write("<script language=JavaScript> myAlert('Message Header Here','Hi select a valid date'); </script>");

Hope that helps you, or someone else!

┊风居住的梦幻卍 2024-08-21 12:28:13

这里有一个相当不错的“黑客” - https://stackoverflow.com/a/14565029,您使用带有空的 iframe src 来生成警报/确认消息 - 它在 Android 上不起作用(出于安全考虑) - 但可能适合您的场景。

There's quite a nice 'hack' here - https://stackoverflow.com/a/14565029 where you use an iframe with an empty src to generate the alert / confirm message - it doesn't work on Android (for security's sake) - but may suit your scenario.

江城子 2024-08-21 12:28:13

您可以做一些调整,在顶部留下一个空行。

像这样。

        <script type="text/javascript" >
            alert("USER NOTICE "  +"\n"
            +"\n"
            +"New users are not allowed to work " +"\n"
            +"with that feature.");
        </script>

You can do a little adjustment to leave a blank line at the top.

Like this.

        <script type="text/javascript" >
            alert("USER NOTICE "  +"\n"
            +"\n"
            +"New users are not allowed to work " +"\n"
            +"with that feature.");
        </script>
不喜欢何必死缠烂打 2024-08-21 12:28:13

是的,你可以改变它。如果您在 Javascript 中调用 VBscript 函数。

这是一个简单的例子

<script>

function alert_confirm(){

      customMsgBox("This is my title","how are you?",64,0,0,0);
}

</script>


<script language="VBScript">

Function customMsgBox(tit,mess,icon,buts,defs,mode)
   butVal = icon + buts + defs + mode
   customMsgBox= MsgBox(mess,butVal,tit)
End Function

</script>

<html>

<body>
<a href="javascript:alert_confirm()">Alert</a>
</body>

</html>

Yes you can change it. if you call VBscript function within Javascript.

Here is simple example

<script>

function alert_confirm(){

      customMsgBox("This is my title","how are you?",64,0,0,0);
}

</script>


<script language="VBScript">

Function customMsgBox(tit,mess,icon,buts,defs,mode)
   butVal = icon + buts + defs + mode
   customMsgBox= MsgBox(mess,butVal,tit)
End Function

</script>

<html>

<body>
<a href="javascript:alert_confirm()">Alert</a>
</body>

</html>
抚你发端 2024-08-21 12:28:13

当我想更改默认确认框的框标题和按钮标题时,我遇到了类似的问题。我已经使用了 Jquery Ui 对话框插件 http://jqueryui.com/dialog/#modal-confirmation

当我有以下内容时:

function testConfirm() {
  if (confirm("Are you sure you want to delete?")) {
    //some stuff
  }
}

我已将其更改为:

function testConfirm() {

  var $dialog = $('<div></div>')
    .html("Are you sure you want to delete?")
    .dialog({
      resizable: false,
      title: "Confirm Deletion",
      modal: true,
      buttons: {
        Cancel: function() {
          $(this).dialog("close");
        },
        "Delete": function() {
          //some stuff
          $(this).dialog("close");
        }
      }
    });

  $dialog.dialog('open');
}

可以在此处看到工作 https:// jsfiddle.net/5aua4wss/2/

希望有帮助。

I had a similar issue when I wanted to change the box title and button title of the default confirm box. I have gone for the Jquery Ui dialog plugin http://jqueryui.com/dialog/#modal-confirmation

When I had the following:

function testConfirm() {
  if (confirm("Are you sure you want to delete?")) {
    //some stuff
  }
}

I have changed it to:

function testConfirm() {

  var $dialog = $('<div></div>')
    .html("Are you sure you want to delete?")
    .dialog({
      resizable: false,
      title: "Confirm Deletion",
      modal: true,
      buttons: {
        Cancel: function() {
          $(this).dialog("close");
        },
        "Delete": function() {
          //some stuff
          $(this).dialog("close");
        }
      }
    });

  $dialog.dialog('open');
}

Can be seen working here https://jsfiddle.net/5aua4wss/2/

Hope that helps.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文