【问题标题】:Adding CSS To iframe in Shopify在 Shopify 中将 CSS 添加到 iframe
【发布时间】:2017-09-05 07:55:51
【问题描述】:

我在 shopify 的 iframe 中添加 Css。但它不工作.. 这是我的代码。

<script>
 $('#twitter-widget-0').load(function() {
  var css = '<style type="text/css"> body {background: white};</style>';
  $('#twitter-widget-0').contents().find("head").append(css);
});
    </script>

【问题讨论】:

  • 使用.css函数。 $('#twitter-widget-0').contents().find("head").css('background-color','white')
  • 它仍然无法正常工作。你还有其他选择吗?
  • 你确定你的 jquery 选择器是正确的吗?它是否指向正确的 DOM?
  • 很确定,实际上我正在尝试更改 iframe 中

    标记的样式。如果您有其他代码。你能帮帮我吗?

  • 你不能像这样将 html 注入到 iframe 中。出于安全考虑,不允许这样做

标签: javascript html css iframe shopify


【解决方案1】:

使用下面的代码。如果你的 DOM 是正确的。

<script>
 $('#twitter-widget-0').load(function() {
  var css = '<style type="text/css"> body {background: white}</style>';
  $('#twitter-widget-0').contents().find("head").append(css);
});
    </script>

【讨论】:

    【解决方案2】:

    我得到了答案

      <script>$(document).ready(function(){$('#twitter-widget-0').load(function() {var css = '<style type="text/css"> body {background: white;}</style>';$('#twitter-widget-0').contents().find("head").append(css);}); });
    

    【讨论】:

      猜你喜欢
      • 2011-10-21
      • 1970-01-01
      • 2013-12-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-20
      相关资源
      最近更新 更多