0

ユーザーのセッションが期限切れになり、デフォルトページがマスターページの下で参照されるときに、ユーザーをdefault.aspxにリダイレクトしています。Twitterのような通知を表示してSession Expired、FirefoxとGoogle Chromeでは正常に機能しますが、IEでは機能しないことを示します。私は得るInternet Explorer cannot open site-http://localhost:1335/order/Default.aspx?Sid=1 Operation aborted

これをグーグルで検索したところ$(document.body).append()、bodyタグが問題になる前に、スクリプトをページの下部に移動すると、どのブラウザでも通知が機能しないことがわかりました。

これが私のマスターページです、

<head runat="server">
    <title></title>

    <script src="Javascript/Jquery1.4.js" type="text/javascript"></script>

    <script type="text/javascript">
        function topBar(message) {
            $("#alertmsg").remove();
            var $alertdiv = $('<div id = "alertmsg"/>');
            $alertdiv.text(message);
            $alertdiv.bind('click', function() {
                $(this).slideUp(200);
            });
            $(document.body).append($alertdiv);
            $("#alertmsg").slideDown("slow");
            setTimeout(function() { $alertdiv.slideUp(200); }, 5000);
        }
    </script>

    <asp:ContentPlaceHolder ID="head" runat="server">
    </asp:ContentPlaceHolder>
</head>
<body>

そして私のtopbar関数は私のdefault.aspxページで呼び出されます。

protected void Page_Load(object sender, EventArgs e)
{
    Int64 id = GetId(Request.RawUrl.ToString());
  if (id == 1)
  {
    ScriptManager.RegisterClientScriptBlock(Page, this.GetType(), "json", "topBar('Session Expired');", true);
  }
}
4

1 に答える 1

1

呼び出される場所が見つかりませんでしたが、topBarそこから呼び出すと$(document).ready()、IE8の魅力のように機能しました。

<script type="text/javascript"> 
    function topBar(message) { 
        $("#alertmsg").remove(); 
        var $alertdiv = $('<div id = "alertmsg"/>'); 
        $alertdiv.text(message); 
        $alertdiv.bind('click', function() { 
            $(this).slideUp(200); 
        }); 
        $(document.body).append($alertdiv); 
        $("#alertmsg").slideDown("slow"); 
        setTimeout(function() { $alertdiv.slideUp(200); }, 5000);
    }

    $(document).ready(function() {
        topBar("Hello world!");
    });
</script> 

が呼び出される$(window).load()前にロードする必要のあるグラフィックやその他の重い要素がある場合にも使用できます。topBar()

$(window).load(function() {
    topBar("Hello world!");
});

それが役に立てば幸い。

編集:


多分これはいくつかの助けになることができますか?基本的に、次のようなことができます。

ScriptManager.RegisterClientScriptBlock(this, typeof(Page), "json",  
    @"$(document).ready(function(){   
             topBar("Hello world!");
             }); 
        });", true); 

彼はいくつかの選択肢を与えているので、リンクの答えをチェックしてください

于 2010-08-19T05:25:55.053 に答える