如果用户点击浏览器取消按钮,隐藏正在加载的gif的最佳方式

Best way to hide a loading gif if the user clicks the browser cancel button?

本文关键字:加载 gif 方式 最佳 隐藏 用户 浏览器 按钮 取消 如果      更新时间:2023-09-26

目前我有一个剑道菜单与一个javascript函数弹出加载gif。

 Html.Kendo().Menu()
                .Name( "menu" )
                .Orientation(MenuOrientation.Vertical)
                .Items( items =>
                {
                    items.Add().Text( "Company Info" ).Items( cInfoItems =>
                    {
                        cInfoItems.Add().Text( "Long Load" ).Url("/Controller/ActionMethod").LinkHtmlAttributes(new{ onclick="return LoadingGif();"});
                    } );

<script>
    function LoadingGif(){
        $('#divLoading').show();
    }
</script>

问题是,当视图正在渲染时,如果用户单击浏览器取消按钮,gif永远不会隐藏。最优雅/圆滑的处理方式是什么?

该死!这是一个老帖子,但仍然没有得到答复?无论如何,对于那些访问过这个页面并滚动寻找答案的人,你可以处理这个问题的一种方法是,

  $(document).ready(function () {
    // Hide the model or a div; whatever you are using
    $(".modal").hide();
    //listen for the submit button click
    $("#myForm").submit(function (event) {
        $(".modal").show();
        // set a timeout to hide the gif
        setTimeout(function () { $('.modal').hide(); }, 2500);
      });
    });

即添加超时。但这不是最好的方法!