简体   繁体   English

显示动画的gif文件,直到重定向asp页面加载?

[英]show the animated gif file until asp page load while redirect?

When I click the redirect button, asp.net project redirect one html file And it show a loader (animated gif) to the user. 当我单击重定向按钮时,asp.net项目重定向一个html文件并向用户显示加载器(动画gif)。 Then it redirect to the particular page. 然后它重定向到特定页面。 Its works fine. 它的工作正常。

But now I not need the redirect page intermediate. 但现在我不需要重定向页面中间。 When I Click the Redirect button, it show the particular asp page, and loader (animated gif) shows center in same page untill it loads. 当我单击重定向按钮时,它显示特定的asp页面,加载器(动画gif)显示在同一页面中心,直到它加载。 After the page loaded - loader (animated gif) has to hide. 页面加载后 - 加载器(动画gif)必须隐藏。 How can I do this?. 我怎样才能做到这一点?。 Give a sample. 给一个样本。

C# Code - C#代码 -

Response.Redirect("Redirecting.html?AvailResults.aspx");

Redirecting.html Code - Redirecting.html代码 -

<body>
<div style='position:absolute;z-index:5;top:45%;left:45%;'>
    <img id="imgAjax" alt="loading..." title="loading..." src="images/ajax-loading.gif" style="width: 100px; height: 100px" /><br /> <br />
 </div>

<script type="text/javascript">
    /* <![CDATA[ */
    this.focus(); //focus on new window

    redirect = function() {
        var querystring = window.location.search.substring(1); //first query string
        var page = querystring.substring(querystring.indexOf('=') + 1, querystring.length);
        function toPage() {
            if (page !== undefined && page.length > 1) {
                document.write('<!--[if !IE]>--><head><meta http-equiv="REFRESH" content="1;url=' + page + '" /><\/head><!--<![endif]-->');
                document.write(' \n <!--[if IE]>');
                document.write(' \n <script type="text/javascript">');
                document.write(' \n var version = parseInt(navigator.appVersion);');
                document.write(' \n if (version>=4 || window.location.replace) {');
                document.write(' \n window.location.replace("' + page + '");');
                document.write(' document.images["imgAjax"].src = "images/ajax-loading.gif"');
                document.write(' \n } else');
                document.write(' \n window.location.href="' + page + '";');
                document.write(' \n  <\/script> <![endif]-->');
            }
        }
        return {
            begin: toPage
        }
    } ();

    redirect.begin();

    /* ]]> */
</script>  
</body>

The problem here is you can't remove the intermediate step AND show/hide your spinner on a different url (you would have already redirected by the time it loaded). 这里的问题是你不能删除中间步骤并在不同的URL上显示/隐藏你的微调器(你可能已经加载时重定向)。 You need a page to load the ajax spinner. 您需要一个页面来加载ajax微调器。 I see two choices: 我看到两个选择:

Option 1: go back to the way you were doing it (click redirect button, go to redirect page with spinner, then redirect to the final destination). 选项1:回到你的方式(点击重定向按钮,转到带有微调器的重定向页面,然后重定向到最终目的地)。 This is similar those "You're now leaving xyz.com" splash pages that forums often use... 这类似于“你现在正在离开xyz.com”的论坛经常使用的启动页面......

Option 2: add an iFrame to your redirect page so you can both show/hide the spinner and load the destination page (in the iframe) at the same time. 选项2:向重定向页面添加iFrame,以便您可以同时显示/隐藏微调器并加载目标页面(在iframe中)。 (If you're redirecting to your own pages in an app or keeping the host the same, you should be able to avoid cross-site issues and ensure the destination pages don't contain frame-breakout scripts etc) (如果您在应用程序中重定向到自己的页面或保持主机相同,则应该能够避免跨站点问题并确保目标页面不包含帧分支脚本等)

Here's what that might look like: 这可能是这样的:

<div style='position:absolute;z-index:5;top:45%;left:45%;'>
  <img id="imgAjax" alt="loading..." title="loading..." src="images/ajax-loading.gif" style="width: 100px; height: 100px" />
</div>

<iframe src="about:blank" id="ifRedir" onload="$('#imgAjax').hide();" style="width:100%;height:100%;border:0px;"</iframe>

<script type="text/javascript">
    $(document).ready(function () {
        $('#ifRedir').attr('src', location.search.substr(1));
    });
</script>  

I think it's always better for a child page in a frame to tell a parent frameholder when it's done loading (you could do this via window.onload and a "parent." call). 我认为框架中的子页面在完成加载时告诉父框架是更好的(您可以通过window.onload和“parent。”调用来执行此操作)。 Without this type of interaction the page will load (and hide the loading spinner) before all pages assets (images) are fully loaded. 如果没有这种类型的交互,页面将在所有页面资源(图像)完全加载之前加载(并隐藏加载微调器)。

You could avoid this by removing the code and instead using: 你可以通过删除代码来避免这种情况,而是使用:

<script type="text/javascript">
    $(document).ready(function () {
        $('#ifRedir').attr('src', location.search.substr(1));
        setTimeout(function () { $('#imgAjax').hide(); }, 1000);
    });
</script>  

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Mvc:在将大型Excel文件加载到数据库时显示动画gif以获得进度 - Mvc: show animated gif for progress while loading big excel file to database 加载文件时显示带有动画gif的弹出窗口 - Display pop up with animated gif while loading file 如何显示加载图像,直到保存数据并通过单击Asp.Net MVC中的按钮重定向到另一页? - How to show loading image until save data and redirect to another page by button click in Asp.Net MVC? 每当页面加载时间过长时,显示加载的Gif动画 - show loading Gif animation whenever page gets time too load 如何在树状视图中显示动画gif? - How to show animated gif in tree views? PictureBox 可以在 Windows 应用程序中显示动画 GIF 吗? - Can a PictureBox show animated GIF in Windows Application? 如何显示中间页/消息“正在生成报告”,直到ASP.NET MVC中服务器上的文件可用 - How to show an intermediate page/message “Generating report” until a file is available on server in ASP.NET MVC 在Winforms中显示动画gif而不锁定文件 - Showing animated gif in Winforms without locking the file 将 animated.gif 文件转换为.bmp 条带 - Converting animated .gif file into a .bmp strip 在X时间内在C#中加载动画GIF图像 - Load animated GIF image in C# during X time
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM