You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Google Tag Manager中移除JS返回结果里的双引号(\x22)

Solution to Remove Double Quotes from H1 Text

Got it, let's fix this up for you! Your current code successfully grabs the H1 text, but when there are double quotes in the content, you want to strip them entirely instead of dealing with escaped characters. Here's the adjusted code:

function() {
  var name = document.querySelector('h1').textContent.replace(/"/g, '');
  return name;
}

How this works:

  • We add the replace() method to the text content of your H1 element.
  • The regex /"/g targets all double quotes in the text (the g flag stands for "global"—it ensures we don't stop at the first quote we find).
  • Replacing each matched quote with an empty string ('') removes every double quote from the final result.

For your example <h1>5" Boning Knife</h1>, this modified code will return 5 Boning Knife exactly as you need.

If you ever wanted to replace quotes with something else (like a space or a different character), you just swap the empty string for your desired replacement value.

内容的提问来源于stack exchange,提问作者chappers

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.25 08:06:13