How to make the contents inside an iframe responsi

2019-07-19 16:45发布

问题:

I have embedded a player from a site which streams a channel using an iframe. I am able to make the iframe responsive. But the content i.e the video player inside the iframe is not adaptive to the changes in viewport. I have tried several solutions from internet but all of them make the iframe responsive but not the content inside.

Is there any way I can make the video player inside the iframe responsive?

Please note that I don't have access to the source code of the player.

Here's the link to the html file: IFrame Code (I was not able to create a working fiddle of this. So shared the file instead)

回答1:

Please note that I don't have access to the source code of the player.

You are in trouble

The one major thing to know while dealing with iframe is the source of the iframe

  • iframe source has the same domain as the main page which renders this iframe: In this case the browser will let you put your hands on the iframe contents and manipulate it as desired. As both the main site and the iframe are unders same domain it means you are a authorized person so you can change the contents if required.

    So even if you don't have access to the source code of the file there are still way's to make your contents responsive if they are in the same domain. This would require Jquery

  • iframe source domain is not the same as your main page which renders this iframe: In this case you cannot do much with the iframe except displaying it in your page. The browser will not allow you to change any stuff on this iframe. This is a security protocol followed in all the browsers.

    • what happens if at all we are given access to manipulate the contents - Eg: I can render youtube in my iframe of my website and change all the instances of the string "youtube" to my own name, thus making this entire site look like my own. Also I can manipulate the ajax calls, jquery stuff etc,etc.. and get data from the site.