我的页面中有一个iframe。像这样:如何获取iframe内容宽度?
<iframe width="600px">
<html>
<head>
</head>
<body>
<p>Some text</p>
<img src="/foo/bar/test.png" />
</body>
</html>
</iframe>
我希望能够检测iframe内容是否大于600px。我试过这个:
var iframe = $('iframe');
if (iframe.width() < iframe.contents().width()) {
console.log('contents larger than the iframe');
}
它适用于Firefox和Internet Explorer。但不是在Chrome上。在Chrome,iframe.contents().width()
为600
我试图iframe.contents().find('body').width()
但结果也是600
我怎么能检测的iframe内容真实宽度在Chrome?
$('iframe')。outerWidth()show? – Thariama
它也显示600。 – Magus