$(document.body).append() doesn't seem to work in IE

后端 未结 1 856
长发绾君心
长发绾君心 2021-01-26 18:31

I am redirecting my user to my default.aspx when his session expires and default page is referenced under a master page. I show a notification like twitter stating Session

相关标签:
1条回答
  • 2021-01-26 19:19

    I could not find the place where topBar is called, but if I call it from $(document).ready() it worked like a charm in my 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> 
    

    You could also use $(window).load() if you have graphics and/or other heavy elements that needs to be loaded before topBar() is called:

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

    Hope it helps.

    EDIT:


    Maybe this can be of some help? Basically you could do something like this:

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

    Check out the answer in the link because he gives a couple of alternatives

    0 讨论(0)
提交回复
热议问题