简体   繁体   English

是否可以在加载后修改经典ASP页面中的iframe内容

[英]Is it possible to modify an iframe contents in a classic ASP page after it has loaded

I have a classic ASP page which is loading an ASP.net page through an iframe inside the ASP page. 我有一个经典的ASP页面,它通过ASP页面内的iframe加载ASP.net页面。 This is working great except for the fact that it takes a while to load the ASP.net page. 这很有效,除了加载ASP.net页面需要一段时间。 The user is left here with unfavorable experience because all they say is an empty blank page until the page is finish loading. 用户留在这里有不愉快的经验,因为他们所说的只是一个空的空白页,直到页面完成加载。

What I would like to do is load an initial "loading" ASP.net page so at least the user is shown something and then when the ASP.net page is ready load the correct ASP.net page into the iframe. 我想要做的是加载一个初始的“加载”ASP.net页面,以便至少向用户显示一些东西,然后当ASP.net页面准备就绪时,将正确的ASP.net页面加载到iframe中。

Is this possible? 这可能吗? I'm thinking perhaps with a bit of javascript but not 100% sure. 我想也许有点javascript但不是100%肯定。

You can use JQuery to modify an iframe after the page is loaded. 您可以在加载页面后使用JQuery修改iframe。

Another question on stackoverflow already contains a good example: stackoverflow上的另一个问题已经包含了一个很好的例子:

<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>

There is no "ASP page" once it hits the browser, there is only the resulting HTML. 一旦它到达浏览器就没有“ASP页面”,只有生成的HTML。

You have a few problems here: 你有一些问题:

1) If you put something in the Iframe, it will be over-written as soon as the new page loads. 1)如果你在iframe中放了一些东西,一旦加载新页面就会覆盖它。 So, you cannot use what's in the Iframe to display your message. 因此,您无法使用Iframe中的内容来显示您的消息。

2) How to tell when the Iframe had loaded 2)如何判断iframe何时加载

You need to determine the location and size of the Iframe on your page. 您需要确定页面上Iframe的位置和大小。 You need to position an element over it with your message. 您需要使用您的消息在其上放置一个元素。 Modify the style of an absolutely-positioned element to cover the Iframe using JavaScript. 修改绝对定位元素的样式以使用JavaScript覆盖Iframe。 Most people would use a framework, such as jQuery, to make it a lot easier. 大多数人会使用一个框架,比如jQuery,使它变得更容易。

You then need to detect when the Iframe has loaded and hide this element. 然后,您需要检测Iframe何时加载并隐藏此元素。

You can use this code to determine that the Iframe has loaded: 您可以使用此代码确定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);      
}

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

相关问题 是否可以修改跨域中正在加载的页面 <iframe> ? - Is it possible to modify the page being loaded in the cross-domain <iframe>? Javascript:在页面加载后添加iframe元素 - Javascript: add iframe element after page has loaded 确定何时加载了IFrame的内容 - Determining when contents of an IFrame has loaded 页面加载后是否可以更改CSS样式表? - Is it possible to change css stylesheets after a page has loaded? 延迟后(仅一次)或第一次加载页面上的iFrame后,滚动到页面顶部 - Scroll to top of page after delay (just once) or after an iFrame on page has loaded the first time 使用多功能框扩展名加载页面后,是否可以运行javascript? - Is it possible to run javascript after a page has loaded using a omnibox extension? 页面加载后使用Javascript创建ASP.NET标签 - Creating ASP.NET labels with Javascript after page has loaded 是否可以使用 jquery: on 方法在文档中动态加载的 iframe 内容上触发事件 - Is it possible to trigger an event on dynamically loaded iframe contents in a document with jquery: on method 检查 iframe 内容是否已加载? - Checking if iframe contents are loaded? 如何仅在 iframe 完全加载后显示页面? - How do i display a page ONLY after the iframe has been loaded completely?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM