How to integrate iframe in your content types

I needed to integrate a map from maps.cern.ch in my content type (see my other post: ).

This was pretty easy thanks to the iframe module that allows the use of iframe in fields.
For more information on iframes, see https://www.w3.org/TR/2011/WD-html5-20110525/the-iframe-element.html

The iframe module can be found at: https://www.drupal.org/project/iframe
This module seems up to date for Drupal 8 and covered by the security advisory policy.

Once installed, you have a new field type “iframe”.

You will have to provide the following information:

  • URL: to the framed content
  • Title: title of the iframe
  • Width: in pixels or % *
  • Height: in pixels or %
  • I advise to leave 100% to work fine with CERN template. An easy way to guarantee that is to set the field’s parameters to “URL with height” in Manage Form Display. In that case, the height will not be asked to the authors of content and will be forced to 100%.

Try to keep with relatively simple content (images, pieces of text etc) in the iframe. There are known limitations (cross-site scripting etc) with iframes.

2 Likes

Just an small addition, if you have problems injecting iframe content on Drupal (or in general in any application) check the X-Frame-Options of the source application and validate that it allows to frame on your domain.
More info: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Frame-Options