【问题标题】:pass parent url to iframe - iframe auto resize将父 url 传递给 iframe - iframe 自动调整大小
【发布时间】:2012-03-05 14:29:38
【问题描述】:

我正在使用我在 stackoverflow 上找到的解决方案,它会根据 iframe 的内容自动调整 iframe 的大小。

https://stackoverflow.com/a/362564/258594

我的 iframe 被多个网站使用,因此我需要对帮助文件的调用是动态的,而不是硬编码的。如何将父 url 传递给我的 iframe 以更改以下行。

pipe.src = 'http://www.foo.com/helper.html?height='+height+'&cacheb='+Math.random();

【问题讨论】:

    标签: javascript url iframe autosize


    【解决方案1】:

    最终将 url 添加到 iframe src

    <iframe width="100%" height="100%" src="foo.html#http://www.ParentURL.com"></iframe>
    

    然后在 iframe 源文件中访问它

    URL = window.location.hash.substr(1);
    var height = document.body.scrollHeight;
    var pipe = document.getElementById('helpframe');
    pipe.src = URL + '/helper.html?height='+height+'&cacheb='+Math.random();
    

    【讨论】:

      【解决方案2】:

      第一个解决方案

      <iframe width="100%" height="100%" src="foo.html"></iframe>
      

      第二个解决方案

      <iframe width="auto" height="auto" src="foo.html"></iframe>
      

      foo.html

      <body>
      <div style="width:200px;height:300px;">
      <p>Your all content</p>
      </div>
      </body>
      

      【讨论】:

        猜你喜欢
        • 2021-06-05
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-10-27
        • 2011-04-26
        • 2020-12-27
        • 1970-01-01
        相关资源
        最近更新 更多