【问题标题】:Change parameters in iframe src attribute with jQuery使用 jQuery 更改 iframe src 属性中的参数
【发布时间】:2011-12-05 04:56:45
【问题描述】:

搜索了很多,但没有找到我正在寻找的东西。 我想根据容器的宽度动态调整 iframe 的大小。

HTML:

<div class="row hidden" id="audio">
            <div class="twelvecol last">
            <iframe id="deezer" scrolling="no" frameborder="0" allowTransparency="true" src="http://www.deezer.com/fr/plugins/player?autoplay=false&playlist=true&width=710&height=308&scover=true&type=album&id=42808&title=" width="710" height="308"></iframe>
            </div>
        </div>

感谢 jQuery,我尝试将 div#content 的宽度和高度注入 iframe 的 src 属性的参数中:

<script>
$(document).ready(function(){
        var contentwidth = $('#content').width();
        var contentheight = $('#content').height(); 
        var iframeUrl = 'http://www.deezer.com/fr/plugins/player?autoplay=false&playlist=true&width=' + contentwidth + '&height=' + contentheight + '&scover=true&type=album&id=42808&title=';
        $('#deezer').attr('src', iframeUrl).attr('width', contentwidth).attr('height', contentheight);   
});
</script> 

感谢您的帮助!

【问题讨论】:

  • 你问题中的代码有什么问题?
  • 此代码不会影响 iframe 的宽度。还是 710px
  • 试试.width().height()
  • 检查 contentwidth 和 contentheight 的值是否正确
  • thx amilia 这是正确的值,因为我使用它们来适应 facebook 的宽度,如框 ;-)

标签: jquery iframe parameters attributes src


【解决方案1】:

【讨论】:

  • thx 但在我的情况下改变宽度和高度属性是不够的。我还必须修改 src 属性中的宽度和高度参数
  • 你不能只读取 iframe 的高度/宽度,然后重复使用它吗?
  • @divstudio 请看这个jsfiddle.net/DYxbf我做一个样例测试。
猜你喜欢
  • 2018-09-30
  • 1970-01-01
  • 2023-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-02-24
  • 2019-01-07
  • 1970-01-01
相关资源
最近更新 更多