2015-04-22 69 views

回答

2

使用jQuery:

$('iframe').height(); 
$('iframe').width(); 

编辑 在阐述上述快速和肮脏的答案。 .height().width()会给你的元素的高度和宽度没有填充,边框或边距。

如果你想包括填充和边框,你将需要使用.innerHeight().innerWidth()。下面的示例:

$('iframe').innerHeight(); 
$('iframe').innerWidth(); 

如果你想包括填充和边界,你将需要使用.outerHeight().outerWidth()保证金。实施例下面:

$('iframe').outerHeight(); 
$('iframe').outerWidth(); 

链接上述方法:
https://api.jquery.com/height/
https://api.jquery.com/innerHeight/
https://api.jquery.com/outerHeight/
https://api.jquery.com/width/
https://api.jquery.com/innerWidth/
https://api.jquery.com/outerWidth/

0

使用纯javascript:

document.getElementsByTagName('iframe')[0].getAttribute('width'); 
document.getElementsByTagName('iframe')[0].getAttribute('height');