我生成一個JavaScript警告與下面的C#.NET頁面代碼:如何編輯JavaScript警告框標題?
Response.Write("<script language=JavaScript> alert('Hi select a valid date'); </script>");
它顯示標題標題「從網頁信息」的提示框。
是否可以修改標題?
我生成一個JavaScript警告與下面的C#.NET頁面代碼:如何編輯JavaScript警告框標題?
Response.Write("<script language=JavaScript> alert('Hi select a valid date'); </script>");
它顯示標題標題「從網頁信息」的提示框。
是否可以修改標題?
嘆息...不,你不能。
它的安全/反釣魚功能。
儘管這是一個答案,並且是IN事實是,我已經確定你可以製作你自己的警報版本,它會做你想做的。一個簡單的模式並覆蓋警報函數調用。 – Fallenreaper 2013-01-10 17:19:30
@Fallenreaper停止打破互聯網。 – 2014-01-27 05:33:16
這是一個安全/反釣魚功能?我很好奇,沒有爭辯。 – Tim 2015-01-20 19:27:47
不,這是不可能的。您可以使用自定義JavaScript警告框。
發現使用jQuery
jQuery Alert Dialogs (Alert, Confirm, & 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>
(雖然,我真的希望你不能。)
我們都希望相同 – rahul 2009-12-15 05:28:34
@Chris Fulstow什麼可以解決[這個問題](http://stackoverflow.com/questions/9347654/combo-box-is-getting-vanished-when-an-alert-is -coming) – Tom 2012-02-19 08:53:18
我喜歡vbscript,我希望vbscript會與javascript一起標準化。這樣我可以腳本沒有區分大小寫的混淆,並且所有流行的瀏覽器都會服從我的命令MWHAHAHA – 2016-06-07 08:07:09
按照您問的方式回答問題。
這實際上很簡單(至少在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>");
希望能幫到你,或者別人!
是的,你可以改變它。如果你在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>
嗨@Saeed,它的工作在IE瀏覽器,但它不會在Mozilla和鉻... .... – 2012-08-24 07:30:37
@ManikandanSethuraju它不會在FF和GC工作,因爲他們不支持VBScript。 – atsurti 2013-10-08 00:52:53
覆蓋的JavaScript window.alert()函數。
window.alert = function(title, message){
var myElementToShow = document.getElementById("someElementId");
myElementToShow.innerHTML = title + "</br>" + message;
}
使用此功能,您可以創建自己的alert()
功能。創建一個新的'酷'看對話框(從一些div元素)。
在chrome和webkit中測試過,不知道其他人。
什麼是'someElementId'?我的意思是哪個標籤? – 2013-04-16 08:53:00
'someElementId'就是你設置HTML元素的id。 – 2013-08-25 16:14:20
這裏有一個相當不錯的'黑客' - https://stackoverflow.com/a/14565029您使用帶有空src的iframe生成警報/確認消息 - 它不適用於Android(出於安全考慮) - 但可能適合您的場景。
優秀的,非常有用的... – 2013-05-13 18:35:49
不僅僅是Android的工作。 – 2014-08-23 13:31:10
當你啓動或者只是加入一個基於web應用的項目時,界面的設計可能不錯。否則,這應該改變。爲了Web 2.0應用程序,您將使用動態內容,許多效果和其他內容。所有這些都很好,但沒有人想過設計JavaScript警報並確認框。 這裏是他們的方式,..完全動態的,JS和CSS驅動 創建簡單的HTML文件
<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>
然後創建簡單的js文件名jsConfirmStyle.js。下面是簡單的js代碼
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()'>"+
" "+
"<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();
}
你可以做一個demu plz – 2015-09-12 06:29:17
你可以做一個小的調整留在頂部的空行。
像這樣。
<script type="text/javascript" >
alert("USER NOTICE " +"\n"
+"\n"
+"New users are not allowed to work " +"\n"
+"with that feature.");
</script>
我發現這個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");
});
[JavaScript警告的更改標題]的可能重複(http://stackoverflow.com/questions/4172022/change-title-of-javascript-alert) – Sjoerd 2013-01-25 14:47:24
你知道,警報可以很容易地被用戶禁用?你不應該依賴這些! – 2014-08-29 05:24:38
我認爲問題是針對與所有平臺和瀏覽器兼容的JavaScript,而不是針對VBScript的,這是嚴格的IE和Windows操作,所以它的使用僅限於Windows。 – UserTursty 2012-12-31 20:08:52