通用腳本輸出類 Script.Alert() 在 IE/360 兼容模式正常彈窗,但在 Chrome/360 極速模式下僅輸出腳本文本,不執行。
public static void ResponseScript(string script)
{
HttpContext.Current.Response.Write("<script type=\"text/javascript\">\n//<![CDATA[\n");
HttpContext.Current.Response.Write(script);
HttpContext.Current.Response.Write("\n//]]>\n</script>\n");
}
// ashx 中調用
context.Response.ContentType = "text/plain"; // 錯誤點
Script.AlertAndGoBack("溫馨提示:有重復的用戶!");
ContentType = "text/plain"。text/plain 視為純文本,**不會解析執行內嵌的 <script> 標籤**。// 修改 ashx ProcessRequest 開頭
context.Response.ContentType = "text/html; charset=utf-8";
// 或至少
context.Response.ContentType = "text/html";
ContentType = "text/html"public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "application/json; charset=utf-8";
var result = new { success = true, msg = "操作成功" };
context.Response.Write(Newtonsoft.Json.JsonConvert.SerializeObject(result));
}