programing

JavaScript 알림 상자 제목을 편집하는 방법은 무엇입니까?

sourcejob 2023. 7. 23. 14:12
반응형

JavaScript 알림 상자 제목을 편집하는 방법은 무엇입니까?

C#에 다음 코드가 있는 JavaScript 경보를 생성하고 있습니다.NET 페이지:

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

제목이 "웹 페이지에서 온 메시지"인 알림 상자가 표시됩니다.

제목을 수정할 수 있습니까?

아니, 그럴 수 없다.

보안/피싱 방지 기능입니다.

아니요, 불가능합니다.사용자 정의 Javascript 알림 상자를 사용할 수 있습니다.

jQuery를 사용하여 좋은 것을 찾았습니다.

jQuery Alert 대화상자(Alert, Confirm, and Prompt Replacements)

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>

(하지만, 저는 당신이 그러지 못했으면 좋겠어요.)

헤더 박스 javascript 사용자 지정을 위한 Sweetalert를 찾았습니다.

예를들면

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");
});

Javascript 창을 재정의합니다.alert(경보) 기능.

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

이것으로 당신은 당신만의 것을 만들 수 있습니다.alert()기능.(일부 div 요소에서) 새로운 '멋진' 대화 상자를 만듭니다.

크롬과 웹킷에서 작업하는 것을 테스트했지만 다른 것들은 확실하지 않습니다.

어떻게 질문했는지에 대한 질문에 답하기 위해서입니다.

이것은 사실 정말 쉽습니다. (적어도 인터넷 익스플로러에서는) 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>");

그게 당신이나 다른 누군가에게 도움이 되길 바랍니다!

https://stackoverflow.com/a/14565029 에는 꽤 괜찮은 '메시지'가 있습니다. ▁where 에서는 빈 src가 있는 iframe을 사용하여 경고/확인 메시지를 생성합니다. Android에서는 작동하지 않지만(보안을 위해) 당신의 시나리오에 적합할 수 있습니다.

상단에 빈 줄을 남기도록 약간의 조정을 할 수 있습니다.

이것처럼.

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

네, 자바스크립트 내에서 VB스크립트 함수를 호출하면 변경할 수 있습니다.

여기 간단한 예가 있습니다.

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

기본 확인 상자의 상자 제목과 단추 제목을 변경하고자 할 때도 비슷한 문제가 있었습니다.저는 Jquery Ui 대화상자 플러그인 http://jqueryui.com/dialog/ #http-consistration을 선택했습니다.

다음을 경험했을 때:

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/ 에서 작업하는 모습을 볼 수 있습니다.

도움이 되길 바랍니다.

언급URL : https://stackoverflow.com/questions/1905289/how-to-edit-a-javascript-alert-box-title

반응형