首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法在redirection.ASP.NET之前打开警报框

无法在redirection.ASP.NET之前打开警报框
EN

Stack Overflow用户
提问于 2011-06-29 01:47:33
回答 1查看 615关注 0票数 0

我试图在重定向之前显示一个警告框,但它不是working.The警告框,只有在重定向没有完成的情况下才有效。

我修改了Mads Kristensen中流行的Alert.Show("string")类,如下所示……

代码语言:javascript
复制
public static class Alert
{

    /// <summary> 
    /// Shows a client-side JavaScript alert in the browser. 
    /// </summary> 
    /// <param name="message">The message to appear in the alert.</param> 

    public static void Show(string message)
    {
        // Cleans the message to allow single quotation marks 
        string cleanMessage = message.Replace("'", "\\'");

       //replacing  script string with strSCript
        //string script = "<script type=\"text/javascript\">alert('" + cleanMessage + "');</script>";

        //added this below
        string strScript = "<script type=\"text/javascript\" language=\"javascript\">";
        strScript += "alert('" + cleanMessage + "');";
        strScript += "window.location.href='http://localhost/Gadgeteer/IncToH/IncToH.zip';";
        strScript += "</script>";


        // Gets the executing web page 
        Page page = HttpContext.Current.CurrentHandler as Page;

        // Checks if the handler is a Page and that the script isn't allready on the Page 
        if (page != null && !page.ClientScript.IsClientScriptBlockRegistered("alert"))
        {
            page.ClientScript.RegisterClientScriptBlock(typeof(Alert), "alert", strScript);

        }
    }

}
//calling from code behind
Alert.Show("message");
EN

回答 1

Stack Overflow用户

发布于 2011-06-29 02:33:43

您可能在alert函数中有一些错误的东西,这是失败的,但重定向不是。请查看呈现给浏览器的内容,并考虑改进您的警报消息。如果消息是动态的,请注意避免使用XSS。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/6510852

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档