You can retrieve the actual height and width of the video content within an iframe using the following jQuery code:
$(document).ready(function(){
var iframe = $('#yourIframeID').get(0);
var iframeDoc = iframe.contentDocument || iframe.contentWindow.document;
var video = iframeDoc.getElementsByTagName('video')[0];
//获取video元素
if(video.readyState >= 2) { //确认视频源已准备就绪
var realWidth = video.videoWidth; //获取真实宽度
var realHeight = video.videoHeight; //获取真实高度
$('#yourIframeID').css({ //设置iframe的高宽为真实高宽
'width': realWidth,
'height': realHeight
});
}
});among, #yourIframeID This is the ID of the iframe you are using; you can modify it as needed. Additionally, please note that due to security policy restrictions, cross-domain issues may arise. If you are making a cross-domain request, ensure that the video source within the iframe you are using is hosted under the same domain as the parent page.