GTM 在模板中发现无效的 HTML、CSS 或 JavaScript

Posted

技术标签:

【中文标题】GTM 在模板中发现无效的 HTML、CSS 或 JavaScript【英文标题】:GTM Invalid HTML, CSS, or JavaScript found in template 【发布时间】:2022-01-22 15:33:44 【问题描述】:

我在下面的代码中使用了 GTM 的“自定义 html 标记”选项,但是当我尝试发布它时它给了我以下错误:在模板中找到无效的 HTML、CSS 或 javascript

我看到其他线程似乎 GTM 不支持或识别某些标签属性。我已经测试了我的代码,控制台中也没有出现错误提示。这是一个标准的引导模式:

function myFunction() 
  var copyText = document.getElementById("myInput");
  navigator.clipboard.writeText(copyText.innerHTML);

  var testtip = document.getElementById("myTooltip");
  testtip.innerHTML = "Copied: " + copyText.innerHTML;


function outFunc() 
  var testtip = document.getElementById("myTooltip");
  testtip.innerHTML = "Copy";


$("#myModal").modal();
body 
  font-family: 'Varela Round', sans-serif


.modal-login 
  color: #636363;
  max-width: 850px;
  width: 100%;
  margin: 30px auto;
  background-image: none!important


.modal-login .modal-content 
  padding: 20px;
  min-height: 586px;
  border-radius: 5px;
  margin: 1rem;
  background-color: #eaebeb;
  background-image: url(https://media-services.dcm-inc.com/couponsites/static/resources/img/festival.png);
  background-size: 100%;
  background-repeat: no-repeat


.modal-login .modal-header 
  border-bottom: none;
  position: relative;
  justify-content: center;
  margin-top: 130px


.modal-login img 
  display: block;
  height: 100%;
  margin-left: auto;
  margin-right: auto;
  width: 40%


.modal-login .form-group 
  position: relative


.modal-login h4 
  text-align: center;
  font-size: 20px;
  width: 80%;
  display: block;
  margin-left: auto;
  margin-right: auto


.modal-login i 
  position: absolute;
  left: 13px;
  top: 11px;
  font-size: 18px


.modal-login .form-control 
  display: block;
  margin-left: auto;
  margin-right: auto;
  width: 40%


@media screen and (max-width:600px) 
  .modal-login .form-control 
    display: block;
    margin-left: auto;
    margin-right: auto;
    width: 80%
  


.modal-login .form-control:focus 
  border-color: #fcda7b


.modal-login .btn,
.modal-login .form-control 
  min-height: 40px;
  border-radius: 30px


.modal-login .hint-text 
  text-align: center;
  padding-top: 10px


.modal-login .close 
  position: absolute;
  top: -5px;
  right: -5px


.button,
.modal-login .btn 
  background: linear-gradient(90deg, #fcda7b 0, #fd5c88 100%);
  border: none;
  line-height: normal


.modal-login .custom 
  display: block;
  margin-left: auto;
  margin-right: auto;
  width: 20%


@media screen and (max-width:600px) 
  .modal-login .custom 
    display: block;
    margin-left: auto;
    margin-right: auto;
    width: 50%
  


.modal-login .custom-social 
  display: block;
  margin-left: auto;
  margin-right: auto;
  width: 30%


.modal-login .btn:focus,
.modal-login .btn:hover 
  opacity: .7


.trigger-btn 
  display: inline-block;
  margin: 100px auto


.contest-social 
  padding: 10px;
  font-size: 30px;
  width: 50px;
  text-align: center;
  text-decoration: none;
  margin: 5px 2px;
  border-radius: 50%


.modal-login .fa:hover 
  opacity: .7


.modal-login .contest-social-facebook 
  background: linear-gradient(90deg, #fcda7b 0, #fd5c88 100%)!important;
  color: #fff


.modal-login .contest-social-twitter 
  background: linear-gradient(90deg, #fcda7b 0, #fd5c88 100%)!important;
  color: #fff


.modal-login .contest-social-youtube 
  background: linear-gradient(90deg, #fcda7b 0, #fd5c88 100%)!important;
  color: #fff


.modal-login .contest-social-instagram 
  background: linear-gradient(90deg, #fcda7b 0, #fd5c88 100%)!important;
  color: #fff


.flex 
  display: -webkit-box;
  display: -ms-flexbox;
  display: flex


.flexC 
  display: -webkit-box;
  display: -ms-flexbox;
  display: flex;
  justify-content: center;
  align-items: center;
  flex-flow: row wrap;
  -webkit-flex-flow: row wrap


.modal-title img 
  margin: 1rem;
  max-width: 100px;
  border-radius: 10px;
  box-shadow: 0 0 3px 3px #ddd


.modal-title p 
  font-size: 20px;
  font-weight: 500;
  max-width: 300px;
  color: #000


.ccme 
  color: #fd5c88


.codelinkbox 
  margin: 0;
  position: relative;
  text-align: center;
  width: auto;
  position: relative


.codeValue 
  border: 2px dashed currentColor;
  font-size: 28px;
  height: 50px;
  line-height: 48px;
  padding: 0 15px;
  border-right: none;
  border-radius: 0;
  display: inline-block;
  white-space: nowrap;
  cursor: pointer;
  border-radius: 6px 0 0 6px!important;
  font-weight: 700;
  color: #000


.buttonBtn.copy 
  background-color: currentColor;
  cursor: pointer;
  font-size: 16px;
  height: 50px;
  line-height: 42px;
  margin: 0;
  padding: 0 15px;
  position: relative;
  text-transform: capitalize;
  overflow: hidden;
  min-width: 0;
  -webkit-transition: all .3s linear;
  -o-transition: all .3s linear;
  transition: all .3s linear;
  border-radius: 0 6px 6px 0


.buttonBtn.copy:hover 
  background: #6ba62c;
  color: #fff


.copy span 
  color: #fff


.m1 
  margin: 1rem auto


.txtC 
  text-align: center


.buttonBtn 
  position: relative;
  cursor: pointer;
  font-size: 15px;
  left: 0;
  top: 0;
  margin: 0;
  height: 54px;
  min-width: 180px;
  border: 0;
  outline: 0;
  padding: 0 15px;
  border-radius: 10px;
  line-height: 54px


.arrRight 
  color: #fff;
  font-weight: 700


.arrRight:after 
  content: '\2192';
  display: inline-block;
  color: #fff


.emailIcon 
  width: 24px;
  max-width: 24px;
  margin: 0 5px


.termsto 
  margin: 3rem 0


.sendemail 
  font-size: 13px;
  margin: 10px 0


@media all and (max-width:540px) 
  .modal-title 
    text-align: center
  
  .modal-login .modal-header 
    margin-top: 40px
  


.testtip 
  position: relative;
  display: inline-block;


.testtip .tooltiptext 
  visibility: hidden;
  width: 140px;
  background-color: #555;
  color: #fff;
  text-align: center;
  border-radius: 6px;
  padding: 5px;
  position: absolute;
  z-index: 1;
  bottom: 120%;
  left: 50%;
  margin-left: -75px;
  opacity: 0;
  transition: opacity 0.3s;


.testtip .tooltiptext::after 
  content: "";
  position: absolute;
  top: 100%;
  left: 50%;
  margin-left: -5px;
  border-width: 5px;
  border-style: solid;
  border-color: #555 transparent transparent transparent;


.testtip:hover .tooltiptext 
  visibility: visible;
  opacity: 1;
<link href="https://fonts.googleapis.com/css?family=Roboto%7CVarela+Round" rel="stylesheet">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<!-- Modal HTML -->
<div id="myModal" class="modal fade">
  <div class="modal-dialog modal-login border">
    <div class="modal-content">
      <div class="modal-header">
        <div class="modal-title">
          <div class="flexC">
            <img src="https://res.cloudinary.com/csnetworkco/image/upload/c_scale,h_150,w_150/csnimages/Noon_568012.jpg"  title="Noon Discount Code"   loading="lazy">
            <p>Up To 70% Off Sale + 10% Off Using Noon Coupon Code</p>
          </div>
        </div>
        <div class="modal-body">
          <div class="codelinkbox flexC m1">
            <div id="myInput" class="codeValue">YB26</div>
            <div class="testtip">
              <button class="buttonBtn copy ccme" onclick="myFunction()" onmouseout="outFunc()"><span id="myTooltip">Copy</span></button>
            </div>
          </div>

        </div>
        <div class="row termsto">
          <div class="col-sm-8">
            <p><strong>Things to remember:</strong></p>
            <ul>
              <li>Don't forget to paste the code in the checkout during the purchase</li>
              <li>Get 10% Off for New Customers & 5% Off for Returning Customers. </li>
              <li>Code Usage: 2 times per customer.</li>
              <li>Always contact our customer support team if there is any issues</li>
              <li>You can always share the code</li>
            </ul>
          </div>
          <div class="col-sm-4 txtC ">
            <a href="https://www.noon.com/uae-en/"><button class="buttonBtn ccme button" id=""><span class="arrRight">VISIT SITE </span></button></a>
          </div>
        </div>
      </div>
    </div>
  </div>
</div>

【问题讨论】:

我只是想知道,写该错误消息的小丑是谁。到处禁止innerHTML,然后再试一次。 我删除了所有的 js 和 css,只是试图发布 HTML 模态,它仍然给我同样的错误,似乎 HTML 格式不被 GTM 接受 我发现了问题所在,我在 img 标签中添加了一个属性 loading="lazy",因此抛出了无效的 HTML CSS 或 JS 错误 他们真的需要突出显示的哪一部分代码是问题无论如何谢谢@Teemu 【参考方案1】:

我发现了问题所在,我在 img 标签中添加了一个属性 loading="lazy",因此引发了无效的 HTML CSS 或 JS 错误

他们确实需要突出代码的哪一部分是问题

我删除了上述属性,现在可以发布标签

【讨论】:

以上是关于GTM 在模板中发现无效的 HTML、CSS 或 JavaScript的主要内容,如果未能解决你的问题,请参考以下文章

html Orange ES:BlueKai GTM标签模板

AURIX系列GTM模块中的PWM部分

iframe中css无效

HTML中,li元素定义了样式,然后再某个li元素定义了某class,发现这个class无效,求解释

用于构建项目或个人网站的HTML/CSS模板

text GTM Regex或案例#GTM