Override body style for content in an iframe

前端 未结 10 948
青春惊慌失措
青春惊慌失措 2020-11-22 01:10

How can I control the background image and colour of a body element within an iframe? Note, the embedded body element has a class, and the iframe i

10条回答
  •  盖世英雄少女心
    2020-11-22 01:16

    Override another domain iframe CSS

    By using part of SimpleSam5's answer, I achieved this with a few of Tawk's chat iframes (their customization interface is fine but I needed further customizations).

    In this particular iframe that shows up on mobile devices, I needed to hide the default icon and place one of my background images. I did the following:

    Tawk_API.onLoad = function() {
    // without a specific API, you may try a similar load function
    // perhaps with a setTimeout to ensure the iframe's content is fully loaded
      $('#mtawkchat-minified-iframe-element').
        contents().find("head").append(
         $("")
       );
    };
    

    I do not own any Tawk's domain and this worked for me, thus you may do this even if it's not from the same parent domain (despite Jeremy Becker's comment on Sam's answer).

提交回复
热议问题