代码之家  ›  专栏  ›  技术社区  ›  Keir Finlow-Bates

如何让javascript在一个帧中等待页面在第二个帧中加载

  •  2
  • Keir Finlow-Bates  · 技术社区  · 17 年前

    frame[0] 包含将页面加载到中的脚本 frame[1]

    top.frames[1].location.href = 'http://some_location.com/page.html';
    

    page.html 在执行此操作之前已加载第二帧,我无法使用 onload=...

    3 回复  |  直到 9 年前
        1
  •  3
  •   palindrom    17 年前

    使用框架元素的onload事件

    编辑:

    <frame onload = "if( top.frames[1].location.pathname == '/page.html' " ) alert( 'loaded' )";
    

    或者,如果您将不同的页面加载到同一框架,请使用以下命令:

    <frame onload = "if( top.frames[1].location.pathname != 'about:blank' " ) alert( 'loaded' )";
    

    或

    <frame src = '/dummyInitial.html' onload = "if( top.frames[1].location.pathname != '/dummyInitial.html' " ) alert( 'loaded' )";
    
        2
  •  0
  •   Taryn Frank Pearson    14 年前

    好吧,我这么做了,而且很有效。

    var idInterval;
    function callPage()
    {   top.main.document.location.href = somepage.aspx;
        document.getElementById('divLoading').style.visibility ="visible";
        idInterval = setInterval("validaFrameMain()",50);
    }
    //look if the frame page is complete load
    function validaFrameMain()
    {
      if (top.main.document.readyState != "complete")
      {document.getElementById('divLoading').style.visibility ="visible";}
      else
      { document.getElementById('divLoading').style.visibility ="hidden";;
        clearInterval(idInterval);
        idInterval = nothing;
      }
    }
        3
  •  0
  •   zb226 Steven Lizarazo    9 年前

    如果您无法控制加载页面的源,更重要的是,如果它来自另一个域,那么只有一个答案:

    你不能。

    推荐文章