# Behavior of iframes within oneboxes in emails

**URL:** <https://meta.discourse.org/t/behavior-of-iframes-within-oneboxes-in-emails/40160>\
**Category:** Development\
**Created:** [2016 年2 月 25 日 14:31 UTC](https://meta.discourse.org/t/behavior-of-iframes-within-oneboxes-in-emails/40160 "2016-02-25T14:31:20Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

作者： ![simon](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/simon/32/339122_2.png) [@simon](https://meta.discourse.org/u/simon)\
发布日期： [2016 年2 月 25 日 17:12 UTC](https://meta.discourse.org/t/behavior-of-iframes-within-oneboxes-in-emails/40160/2 "2016-02-25T17:12:09Z")

</div>

It’s all happening in `lib/email/styles.rb`.

```rb
  def onebox_styles
     ...
      # iframes can't go in emails, so replace them with clickable links
      @fragment.css('iframe').each do |i|
        begin
          src_uri = URI(i['src'])

          # If an iframe is protocol relative, use SSL when displaying it
          display_src = "#{src_uri.scheme || 'https://'}#{src_uri.host}#{src_uri.path}"
          i.replace "<p><a href='#{src_uri.to_s}'>#{display_src}</a><p>"
        rescue URI::InvalidURIError
          # If the URL is weird, remove it
          i.remove
        end
      end

```

You can add a plugin\_callback to modify the html.

```rb
    # this method is reserved for styles specific to plugin
    def plugin_styles
      @@plugin_callbacks.each { |block| block.call(@fragment, @opts) }
    end

```

Unfortunately, `plugin_styles` is called after `onebox_styles` in the `format_html` method. If that order was reversed you could do what you want.

Doing any work with this file is slow because the methods are being cached by Sidekiq. To get around that I’ve been requiring `sidekiq/testing` at the start of `100-sidekiq.rb` instead of `sidekiq/pausable`. To do that you have to comment out calls to `Sidekiq.pause!` in `restorer.rb` and `backuper.rb`.

The other option is to restart sidekiq every time you change the code.

---

_[View the full topic](https://meta.discourse.org/t/behavior-of-iframes-within-oneboxes-in-emails/40160)._
