【问题标题】:Is it possible to modify an iframe contents in a classic ASP page after it has loaded加载后是否可以修改经典 ASP 页面中的 iframe 内容
【发布时间】:2010-04-27 22:14:54
【问题描述】:

我有一个经典的 ASP 页面,它通过 ASP 页面内的 iframe 加载 ASP.net 页面。除了加载 ASP.net 页面需要一些时间之外,这很好用。用户在这里留下了不利的体验,因为他们所说的只是一个空白页面,直到页面完成加载。

我想做的是加载一个初始的“正在加载”的 ASP.net 页面,以便至少向用户显示一些内容,然后当 ASP.net 页面准备好时,将正确的 ASP.net 页面加载到 iframe 中。

这可能吗?我在想也许有一点 javascript 但不是 100% 确定。

【问题讨论】:

    标签: javascript html asp-classic


    【解决方案1】:

    一旦进入浏览器,就没有“ASP 页面”,只有生成的 HTML。

    这里有几个问题:

    1) 如果您在 iframe 中添加了一些内容,那么一旦新页面加载,它就会被覆盖。因此,您不能使用 iframe 中的内容来显示您的消息。

    2) 如何判断 iframe 何时加载

    您需要确定页面上 iframe 的位置和大小。您需要在消息上放置一个元素。使用 JavaScript 修改绝对定位元素的样式以覆盖 Iframe。大多数人会使用 jQuery 等框架来简化它。

    然后您需要检测 iframe 何时加载并隐藏此元素。

    您可以使用this code 来确定Iframe 已加载:

    function checkIframeLoading() {
       // Get a handle to the iframe element
       var iframe = document.getElementById('testIframe');
    
       // Check if loading is complete
       if ( iframe.document.readyState == 'complete' ) {
          // The loading is complete, call the function we want executed once the iframe is loaded
          functionToCallAfterLoading();
          return;
       }
    
       // If we are here, it is not loaded. Set things up so we check   the status again in 100 milliseconds
       window.setTimeout('checkIframeLoading();', 100);      
    }
    

    【讨论】:

      【解决方案2】:

      您可以在页面加载后使用 JQuery 修改 iframe。

      stackoverflow 上的Another question 已经包含一个很好的例子:

      <html>
        <head>
              <script type="text/javascript" src="jquery.js"></script>
              <script>
            $(document).ready(function(){
                  var locations = ["http://webPage1.com", "http://webPage2.com"];
                  var len = array.length;
                  var iframe = $('#frame');
                  var i = 0;
                  setInterval(function () {
                          $iframe.attr('src', locations[++i % len]);
                  }, 30000);
            });
          </script>
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2017-02-08
        • 1970-01-01
        • 1970-01-01
        • 2012-08-04
        • 1970-01-01
        • 2021-08-08
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多