0

I have a RTE on my site, which allows the user to embed an iframe with a video. The problem is, that when the use embeds an iframe, it automatically sets the height and width to static sizes, which does not work on mobile devices. How do I search and replace the contents of the width and height element of a string, without knowing the actual width and height of the element?

Here is an example of what I would like to do:

I receive this from the view:

<iframe src="someyoutubevideo" height="100px" width="150px"/>

I would like to replace it to:

<iframe src="someyoutubevideo" height="auto" width="100%"/>

The height and width can vary though, so a simple search and replace wont work

Gabriel Castillo Prada
  • 4,114
  • 4
  • 21
  • 31
Jannik
  • 401
  • 1
  • 5
  • 17
  • A regex along the lines of [this](https://www.regextester.com/96026) would do the job (disclaimer: that's not my regex and I haven't validated it in any way) – Diado Apr 30 '18 at 15:40
  • You should use CSS to style your components, this should work better : https://stackoverflow.com/questions/24579785/force-iframe-youtube-video-to-center-fit-and-full-cover-the-screen-in-the-backgr – Deblaton Jean-Philippe Apr 30 '18 at 15:43

1 Answers1

0

I'd do this using jQuery on the client-side. Something like this will do it:

$(function(){
    var $myIFrame = $("iframe[src*='youtube']");
    $myIFrame.prop("height", "100");
});

Disclaimer: I've not done any web coding in years, and CSS is probably a better idea.

Dan Rayson
  • 1,315
  • 1
  • 14
  • 37