Hongmu Notes
Home Language Notes jquery gets the real height and width of the video content in the iframe frame and sets it
Language Notes JavaScript

jquery gets the real height and width of the video content in the iframe frame and sets it

jquery gets the real height and width of the video content in the iframe frame and sets it

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.

微信赞赏

WeChat

支付宝赞赏

Alipay

✍️ Author: Hong Mu

webmaster · Thanks for reading, stay tuned for more exciting content

Author homepage View home page →

Related articles

js move the mouse up to modify the style attribute

js move the mouse up to modify the style attribute Language Notes JavaScript

When the mouse hovers over the element, the color changes to red; when the mouse leaves the element, the color changes to black. To retrieve an element by its ID: `document.getElementById()`; Event handler for mouse hover: `onmouseover`; Event handler for mouse leave: `onmouseout`.<!DOCTYPE html><html lang= "en">...
👁 130

Recommended reading

(Adaptive mobile version) Red-themed machinery and equipment website PBootCMS template – Download a spacious, high-resolution machinery and equipment website source code – 0386

(Adaptive mobile version) Red-themed machinery and equipment website PBootCMS template – Download a spacious, high-resolution machinery and equipment website source code – 0386 Practical Collection pbootcms Template

An adaptive mobile-friendly PbootCMS website template featuring a red-themed mechanical equipment design. The design boasts a spacious, sophisticated, yet warm and professional aesthetic, making it ideal for showcasing various heavy-duty machinery and industrial equipment products. This template helps mechanical equipment companies effectively present their brand image online and attract industrial clients. Template Preview | Installation Instructions | Website Backend: /admin.php | Username: admin | Password: admin | Extraction Password: www.4s5.cn | Related Articles...
👁 41
Responsive, marketing-oriented sports and fitness equipment website template – 0690

Responsive, marketing-oriented sports and fitness equipment website template – 0690 Practical Collection Yiyou template

An eyouCMS responsive website template designed for marketing-oriented fitness equipment manufacturers. Its dynamic and professional design effectively showcases fitness equipment products, workout programs, and brand strength. This template helps fitness equipment manufacturers showcase their products online and attract both gym members and home users. Template Overview | Installation Instructions | Website Backend: /login.php | Username: admin | Password: admin | Related Articles: Common Installation Questions for YouyouCMS...
👁 49
css absolute positioning center

css absolute positioning center Language Notes CSS

There are numerous methods to achieve absolute positioning with centering in CSS; below, we will introduce four such techniques. 1. A widely compatible and mainstream approach for achieving absolute positioning with centering in CSS: `.container {width: 600px; height: 400px; position: absolute; left: 50%; top: 50%; margin:...`
👁 414
(Adaptive mobile version) Bilingual (Chinese/English) international trade website template; Soft管 High-Pressure Pipe Website Template – Download Now (1113)

(Adaptive mobile version) Bilingual (Chinese/English) international trade website template; Soft管 High-Pressure Pipe Website Template – Download Now (1113) Practical Collection pbootcms Template

A bilingual (Chinese/English) PbootCMS website template designed for foreign trade and high-pressure hose applications, compatible with both PC and WAP devices. Its professional, international design is ideal for hose manufacturing companies to showcase their products and export advantages. The multilingual support facilitates effective brand promotion across global markets. Template Preview | Installation Instructions | Website Backend: /admin.php | Username: admin | Password: admin | Extraction Password: www.4s5.cn | Related Articles...
👁 59
(Adaptive mobile version) Green HTML5 minimalist and stylish filter material-based PBootCMS corporate template – Download filter material and stone website source code: 0387

(Adaptive mobile version) Green HTML5 minimalist and stylish filter material-based PBootCMS corporate template – Download filter material and stone website source code: 0387 Practical Collection pbootcms Template

This adaptive mobile-friendly corporate template for PbootCMS features a green, minimalist, and stylish stone filtration material showcase. Its fresh, natural design is ideal for displaying filtration materials, stone products, and other industrial applications. It enables environmental materials companies to showcase their products online and attract clients in the water treatment and construction sectors. Template Display | Installation Instructions | Website Backend: /admin.php | Username: admin | Password: admin | Extraction Password: www.4s5.cn – Related...
👁 50
Locomotive collector generates relevant tags based on collection titles (aggregation pages are created in batches)

Locomotive collector generates relevant tags based on collection titles (aggregation pages are created in batches) Practical Collection High-speed rail collection

If you often make websites, you will definitely find that many programs have a tag field! This field can aggregate related articles to create an effect similar to a list page! When this plug-in is used properly, it is very friendly to website ranking or website optimization! Generate corresponding tags based on the title, and tags are separated by English commas. This means that you can publish it directly to your website without having to modify it again! Come and see the effect!
👁 301