Google再营销代码 - iframe高度问题

Az.*_*Az. 61 css iframe

我注意到Google的再营销代码会在页面底部插入一个iframe.问题是iframe弄乱了我的布局(它高13px,底部留下一个空白的垂直空间).

我试图用css隐藏它,但它在IE9中仍然可见:

iframe[name='google_conversion_frame'] { 
    height: 0 !important; 
    line-height: 0 !important; 
    font-size: 0 !important; 
}
Run Code Online (Sandbox Code Playgroud)

因此我有两个问题:

a)如何在IE9中隐藏这个iframe

b)最重要的是 - 它是否安全还是可以以某种方式影响该脚本的功能?

Sim*_*s82 140

在我的网站中,我使用此代码

iframe[name='google_conversion_frame'] { 
    height: 0 !important;
    width: 0 !important; 
    line-height: 0 !important; 
    font-size: 0 !important;
    margin-top: -13px;
    float: left;
}
Run Code Online (Sandbox Code Playgroud)

浮动iframe允许您使用等于iframe内部主体高度的负边距.

  • 有什么理由不只是`display:none!important`? (2认同)

Az.*_*Az. 31

其他方式(在上面的注释中提到)是将conversion.js脚本标记插入隐藏的div:

<div style="display: none">
    <script type="text/javascript" src="//www.googleadservices.com/pagead/conversion.js">  </script>
</div>
Run Code Online (Sandbox Code Playgroud)

src:http://keanrichmond.com/google-remarketing-messing-with-my-design.html

  • 这实际上可能会阻止某些浏览器加载跟踪iframe,因此我建议在部署到实际网站之前在所有常见浏览器中对此进行测试. (4认同)

小智 22

我有同样的问题.好的解决方案是在google再营销代码中添加一行.

    var google_conversion_format = 3;
Run Code Online (Sandbox Code Playgroud)

修改前的标签:

<!-- Code Google de la balise de remarketing -->
<script type="text/javascript">/* 
<![CDATA[ */
var google_conversion_id = 10xxxxxxxx;
var google_custom_params = window.google_tag_params;
var google_remarketing_only = true;
/* ]]> */
</script>
<script type="text/javascript" src="//www.googleadservices.com/pagead/conversion.js"></script>
<noscript><div style="display:inline;"><img height="1" width="1" style="border-style:none;" alt="" src="//googleads.g.doubleclick.net/pagead/viewthroughconversion/10xxxxxxxx/?value=0&amp;guid=ON&amp;script=0"/></div></noscript>
Run Code Online (Sandbox Code Playgroud)

修改后的标签:

<!-- Code Google de la balise de remarketing -->
<script type="text/javascript">/* 
<![CDATA[ */
var google_conversion_id = 10xxxxxxxx;
var google_custom_params = window.google_tag_params;
var google_remarketing_only = true;

var google_conversion_format = 3; /* ADD THIS LINE TO RESOLVE YOUR PROBLEM */

/* ]]> */
Run Code Online (Sandbox Code Playgroud)


Exc*_*tSP 17

不要使用那些过于复杂的答案.只需使用position:fixed;该元素即可将其从文档流中取出.

像这样:

iframe[name="google_conversion_frame"]{
    position:fixed;
}
Run Code Online (Sandbox Code Playgroud)

而已!您保留所有原始功能,并且您不必担心API更改.