我正在尝试从 Google Analytics 标记中删除特殊字符。我有以下脚本,但我不知道为什么它不起作用。它是 JSP 和 JavaScript 的混合体,我对此知之甚少!在工作学习...
<script type="text/javascript">
function removeSplChars(inStr) {
inStr = inStr.replace(/[^a-zA-Z0-9 ]/g, "");
return inStr;
}
var _gaq = _gaq || [];
_gaq.push(['_setAccount', '<c:out value="${profileId}"/>']);
<c:choose>
<c:when test="${(lastCmdName eq 'CategoryDisplay') or (lastCmdName eq 'ProductDisplay')}" >
_gaq.push(['_setCustomVar',
2, // This custom var is set to slot #2.
'<c:choose><c:when test="${WCParam.source eq 'search'}">Search</c:when><c:otherwise><c:out value="${topCat}" /></c:otherwise></c:choose>', // The top-level name for your online content categories.
'<c:choose><c:when test="${WCParam.source eq 'search'}">Search <c:out value="${WCParam.searchTerm}" /></c:when><c:otherwise><c:out value="${topCat}" />|<c:out value="${subCatA}" />|<c:out value="${subCatB}" />|<c:out value="${subCatC}" /></c:otherwise></c:choose>', // Records value of breadcrumb name
3 // Sets the scope to page-level.
]);
</c:when>
<c:otherwise>
</c:otherwise>
</c:choose>
removeSplChars(<c:out value="${topCat}" />, <c:out value="${subCatA}" />, <c:out value="${subCatB}" />, <c:out value="${subCatC}" />);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
我是否在某处遗漏了一些 () 或某些东西?我得到一个“意外的令牌;” 控制台中的错误消息。我尝试在 $(document).ready(function() {}); 中调用 removeSplChars
无济于事。
我检查了以下帖子,但建议对我没有帮助: 未调用 函数 javascript 函数未被调用
我在这里有另一篇文章:JavaScript Remove special characters string not working
谢谢你。
通过查看源代码添加代码:
<script type="text/javascript">
function removeSplChars(inStr) {
inStr = inStr.replace(/[^a-zA-Z0-9 ]/g, "");
return inStr;
}
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-33021136-1']);
_gaq.push(['_setCustomVar',
2, // This custom var is set to slot #2.
'Dine & Entertain', // The top-level name for your online content categories.
'Dine & Entertain|Bowls & Platters||', // Records value of breadcrumb name
3 // Sets the scope to page-level.
]);
$(document).ready(function() {
removeSplChars(Dine & Entertain, Bowls & Platters, , );
});
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>