How to edit a JavaScript alert box title?

前端 未结 11 2232
执笔经年
执笔经年 2020-11-22 10:15

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

Response.Write(\"

        
相关标签:
11条回答
  • 2020-11-22 10:23

    No, you can't.

    It's a security/anti-phishing feature.

    0 讨论(0)
  • 2020-11-22 10:25

    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!

    0 讨论(0)
  • 2020-11-22 10:27

    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.

    0 讨论(0)
  • 2020-11-22 10:28

    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)

    0 讨论(0)
  • 2020-11-22 10:29

    When you start up or just join a project based on webapplications, the design of interface is maybe good. Otherwise this should be changed. In order to Web 2.0 applications you will work with dynamic contents, many effects and other stuff. All these things are fine, but no one thought about to style up the JavaScript alert and confirm boxes. Here is the they way,.. completely dynamic, JS and CSS driven Create simple html file

    <html>
     <head>
       <title>jsConfirmSyle</title>
       <meta http-equiv="Content-Style-Type" content="text/css" />
       <meta http-equiv="Content-Script-Type" content="text/javascript" />
        <script type="text/javascript" src="jsConfirmStyle.js"></script>
        <script type="text/javascript">
    
          function confirmation() {
           var answer = confirm("Wanna visit google?")
           if (answer){
           window.location = "http://www.google.com/";
           }
         }    
    
        </script>
        <style type="text/css">
         body {
          background-color: white;
          font-family: sans-serif;
          }
        #jsconfirm {
          border-color: #c0c0c0;
          border-width: 2px 4px 4px 2px;
          left: 0;
         margin: 0;
         padding: 0;
         position: absolute;
        top: -1000px;
        z-index: 100;
       }
    
      #jsconfirm table {
       background-color: #fff;
       border: 2px groove #c0c0c0;
       height: 150px;
       width: 300px;
      }
    
       #jsconfirmtitle {
      background-color: #B0B0B0;
      font-weight: bold;
      height: 20px;
      text-align: center;
    }
    
     #jsconfirmbuttons {
    height: 50px;
    text-align: center;
     }
    
    #jsconfirmbuttons input {
    background-color: #E9E9CF;
    color: #000000;
    font-weight: bold;
    width: 125px;
    height: 33px;
    padding-left: 20px;
    }
    
    #jsconfirmleft{
    background-image: url(left.png);
    }
    
    #jsconfirmright{
    background-image: url(right.png);
     }
     < /style>
      </head>
     <body>
    <p><br />
    <a href="#"
    onclick="javascript:showConfirm('Please confirm','Are you really really sure to visit    google?','Yes','http://www.google.com','No','#')">JsConfirmStyled</a></p>
    <p><a href="#" onclick="confirmation()">standard</a></p>
    
    </body>
    </html>
    

    Then create simple js file name jsConfirmStyle.js. Here is simple js code

    ie5=(document.getElementById&&document.all&&document.styleSheets)?1:0;
    nn6=(document.getElementById&&!document.all)?1:0;
    
     xConfirmStart=800;
     yConfirmStart=100;
    
      if(ie5||nn6) {
      if(ie5) cs=2,th=30;
      else cs=0,th=20;
       document.write(
        "<div id='jsconfirm'>"+
            "<table>"+
                "<tr><td id='jsconfirmtitle'></td></tr>"+
                "<tr><td id='jsconfirmcontent'></td></tr>"+
                "<tr><td id='jsconfirmbuttons'>"+
                    "<input id='jsconfirmleft' type='button' value='' onclick='leftJsConfirm()' onfocus='if(this.blur)this.blur()'>"+
                    "&nbsp;&nbsp;"+
                    "<input id='jsconfirmright' type='button' value='' onclick='rightJsConfirm()' onfocus='if(this.blur)this.blur()'>"+
                "</td></tr>"+
            "</table>"+
        "</div>"
      );
       }
    
     document.write("<div id='jsconfirmfade'></div>");
    
    
     function leftJsConfirm() {
      document.getElementById('jsconfirm').style.top=-1000;
      document.location.href=leftJsConfirmUri;
     }
    function rightJsConfirm() {
    document.getElementById('jsconfirm').style.top=-1000;
    document.location.href=rightJsConfirmUri;
     }
    function confirmAlternative() {
    if(confirm("Scipt requieres a better browser!"))       document.location.href="http://www.mozilla.org";
    }
    
    leftJsConfirmUri = '';
    rightJsConfirmUri = '';
    
      /**
       * Show the message/confirm box
      */
        function       showConfirm(confirmtitle,confirmcontent,confirmlefttext,confirmlefturi,confirmrighttext,con      firmrighturi)  {
    document.getElementById("jsconfirmtitle").innerHTML=confirmtitle;
    document.getElementById("jsconfirmcontent").innerHTML=confirmcontent;
    document.getElementById("jsconfirmleft").value=confirmlefttext;
    document.getElementById("jsconfirmright").value=confirmrighttext;
    leftJsConfirmUri=confirmlefturi;
    rightJsConfirmUri=confirmrighturi;
    xConfirm=xConfirmStart, yConfirm=yConfirmStart;
    if(ie5) {
        document.getElementById("jsconfirm").style.left='25%';
        document.getElementById("jsconfirm").style.top='35%';
    }
    else if(nn6) {
        document.getElementById("jsconfirm").style.top='25%';
        document.getElementById("jsconfirm").style.left='35%';
    }
    else confirmAlternative();
    

    }

    You can download full Source code from here

    0 讨论(0)
  • 2020-11-22 10:31

    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.

    0 讨论(0)
提交回复
热议问题