测试文件index.aspx
<SCRIPT LANGUAGE="JavaScript">
var mm = "";
window.alert = function(str)
{
mm = str; //提示的文本
showModalDialog('alert.aspx', window, 'dialogWidth: 400px; dialogHeight:50px; status: no; help: no');
}
window.alert("hello,everyone");
</SCRIPT>alert.aspx文件:
<html>
<head>
<title>翻唱联盟提醒您:</title>
<META http-equiv="pragma" content="no-cache">
<META http-equiv="Cache-Control" content="no-cache, must-revalidate">
<META http-equiv="expires" content="Mon, 23 Jan 1978 12:52:30 GMT">
</head>
<body style="MARGIN: 0px" vLink="#000000" scroll="no" aLink="#ff0000" link="#0066ff" background="images/index_allbg.jpg">
<TABLE style="BORDER-RIGHT: #acacac 1px solid; BORDER-LEFT: #acacac 1px solid" cellSpacing="0"
cellPadding="0" width="400" align="left" border="0">
<TR>
<td valign="top" height="50">
<TABLE cellSpacing="0" cellPadding="0" width="99%" align="center" border="0">
<TR>
<TD width="1"><IMG src="bbs/images/default_talbe_left.gif"></TD>
<TD background="bbs/images/default_talbe_center.gif"> </TD>
<TD width="1"><IMG src="bbs/images/default_talbe_right.gif"></TD>
</TR>
</TABLE>
<TABLE class="table" cellSpacing="0" cellPadding="0" width="99%" align="center" background="bbs/images/default_table_bg.gif"
border="0">
<TBODY>
<tr>
<td vAlign="middle" align="left" width="23%" height="50"><IMG src="bbs/images/bankuai.gif" align="absMiddle"></td>
<td noWrap align="center" width="76%"><font style="FONT-WEIGHT: bold; FONT-SIZE: 9pt; COLOR: #006600">
<div id="haha"></div>
</font>
</td>
</tr>
</TBODY>
</TABLE>
</td>
</TR>
</TABLE>
<script language="javascript">
if (window.dialogArguments != null)
{
var ww = window.dialogArguments;
document.all.haha.innerHTML = ww.mm;
}
</script>
</body>
</html>现在的问题是:你运行index.aspx文件的时候window.alert弹出的确定提示框是我的alert.aspx文件,
但是在index.aspx文件一服务器端按钮中如果写一句Response.Write("<javascript>alert('test');</script>");就又会弹出以前的提示框,如何解决?谢谢。
<SCRIPT LANGUAGE="JavaScript">
var mm = "";
window.alert = function(str)
{
mm = str; //提示的文本
showModalDialog('alert.aspx', window, 'dialogWidth: 400px; dialogHeight:50px; status: no; help: no');
}
window.alert("hello,everyone");
</SCRIPT>alert.aspx文件:
<html>
<head>
<title>翻唱联盟提醒您:</title>
<META http-equiv="pragma" content="no-cache">
<META http-equiv="Cache-Control" content="no-cache, must-revalidate">
<META http-equiv="expires" content="Mon, 23 Jan 1978 12:52:30 GMT">
</head>
<body style="MARGIN: 0px" vLink="#000000" scroll="no" aLink="#ff0000" link="#0066ff" background="images/index_allbg.jpg">
<TABLE style="BORDER-RIGHT: #acacac 1px solid; BORDER-LEFT: #acacac 1px solid" cellSpacing="0"
cellPadding="0" width="400" align="left" border="0">
<TR>
<td valign="top" height="50">
<TABLE cellSpacing="0" cellPadding="0" width="99%" align="center" border="0">
<TR>
<TD width="1"><IMG src="bbs/images/default_talbe_left.gif"></TD>
<TD background="bbs/images/default_talbe_center.gif"> </TD>
<TD width="1"><IMG src="bbs/images/default_talbe_right.gif"></TD>
</TR>
</TABLE>
<TABLE class="table" cellSpacing="0" cellPadding="0" width="99%" align="center" background="bbs/images/default_table_bg.gif"
border="0">
<TBODY>
<tr>
<td vAlign="middle" align="left" width="23%" height="50"><IMG src="bbs/images/bankuai.gif" align="absMiddle"></td>
<td noWrap align="center" width="76%"><font style="FONT-WEIGHT: bold; FONT-SIZE: 9pt; COLOR: #006600">
<div id="haha"></div>
</font>
</td>
</tr>
</TBODY>
</TABLE>
</td>
</TR>
</TABLE>
<script language="javascript">
if (window.dialogArguments != null)
{
var ww = window.dialogArguments;
document.all.haha.innerHTML = ww.mm;
}
</script>
</body>
</html>现在的问题是:你运行index.aspx文件的时候window.alert弹出的确定提示框是我的alert.aspx文件,
但是在index.aspx文件一服务器端按钮中如果写一句Response.Write("<javascript>alert('test');</script>");就又会弹出以前的提示框,如何解决?谢谢。
想想别的方法。
这句话输出的时候,客户端脚本还未加载
<SCRIPT LANGUAGE="JavaScript">
var mm = "";
window.alert = function(str)
{
mm = str; //提示的文本
showModalDialog('alert.aspx', window, 'dialogWidth: 400px; dialogHeight:50px; status: no; help: no');
}
window.alert("hello,everyone");
</SCRIPT>所以不能得到你想要的结果
Response.Write("<javascript>alert('test');</script>")since Response.Write output the string at the top of the page, use Page.RegisterStartupScript instead
cs:
string strAlert = "<script language=\"javascript\">showModalDialog('alert.aspx', window, 'dialogWidth: 400px; dialogHeight:50px; status: no; help: no');</script>";
Response.Write( strAlert);
runat=server的form当然不起作用
<form id="Form1" method="post" runat="server">
<input type="hidden" value="test" id="myhiden">
</form>
后台如下
Page.RegisterStartupScript("","<script>alert('RegisterStartupScript:'+document.all.myhiden.value)</script>");
Page.RegisterClientScriptBlock("","<script>alert('RegisterClientScriptBlock:'+document.all.myhiden.value)</script>");
结果如下:只出现对话框显示RegisterStartupScript:test
查看源代码如下:
<form name="Form1" method="post" action="WebForm4.aspx" id="Form1">
<input type="hidden" name="__VIEWSTATE" value="dDwtNjU0MzcyMTk1Ozs+NmbLf6dWkF/Q/FLKKsdPPfhFXr0=" />
<script>alert('RegisterClientScriptBlock:'+document.all.myhiden.value)</script>
<input type="hidden" value="test" id="myhiden">
<script>alert('RegisterStartupScript:'+document.all.myhiden.value)</script>
</form>
两者区别不用多说了吧
<head>
<script language=javascript>
window.alert=function()
{
showModalDialog("http://www.microsoft.com");
}alert("yes");</script>
</head>
<body>
<form runat="server">
<asp:Button id=btn runat="server" OnClick="TestAlert" Text="Click Me"/>
</form></body>
</html><script language="C#" runat="server">
void TestAlert(Object sender, EventArgs e)
{
Page.RegisterStartupScript("startup", "<script>window.alert('no');</" + "script>");
}
</script>
Response.Write("<script event=onload for=window language=javascirpt>alert('test');</script>")
还有,你注意你的代码:Response.Write("<javascript>alert('test');</script>")
*********
写得不对哦。