我的頁面中有一個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