【问题标题】:Entering a DIV automatically opens link into iframe输入 DIV 会自动打开 iframe 的链接
【发布时间】:2012-06-07 20:50:03
【问题描述】:

我在页面顶部有一个“位置:固定”iframe,在其上方,一个水平菜单(也是固定的)。 每个菜单按钮将整个页面滚动到选定的 div。

有没有办法在到达该 div 后自动打开链接? 我需要自动加载输入“div #1”的“iframe content 1”,输入“div #2”的“iframe content 2”等

页面有 jQuery。

提前致谢。

【问题讨论】:

    标签: iframe html href


    【解决方案1】:

    让我们看看这是否适合你:

    $('#btn1').click(function() {
      var targetOffset = $('#div1').offset().top; 
      $('html,body').animate({scrollTop: targetOffset}, 5000, function() {
        // Animation complete, lets load content
         $('#div1').html($('#iframe1').contents());
      });
    });
    
    /**
    For the contents() to work the iframe must be getting the content from the same domain
    */
    

    【讨论】:

    • 谢谢,我正在努力。使用“#iframe1”你指的是什么?我有一个名为“frame”的 iframe,我在其中加载需要加载的页面(来自同一个域)。 链接
    • 我不使用 target="frame"。我假设你已经用 html 加载了#iframe1,所以我正在滚动到 div,当它完成时,我正在加载 iframe 内容 #div1
    猜你喜欢
    • 2012-06-27
    • 1970-01-01
    • 2012-08-15
    • 2022-09-23
    • 1970-01-01
    • 2023-03-11
    • 2018-01-30
    • 1970-01-01
    • 2017-11-07
    相关资源
    最近更新 更多