Google 애널리틱스 태그에서 특수 문자를 제거하려고합니다. 다음 스크립트가 있는데 작동하지 않는 이유를 알 수 없습니다. JSP와 자바 스크립트가 혼합되어 있습니다. 직장 학습 중 ...함수가 호출되지 않았습니다. - JavaScript 및 JQuery를 시도했습니다.
<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 Remove special characters string not working
감사합니다 : Function is not Called javascript function not getting called
내가 여기에 또 다른 게시물을합니다. removeSplChars
에 전달
<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>
서버 측 마크 업이 아닌 브라우저 [보기 소스]에서 생성 된 코드를 확인하는 것이 항상 좋습니다. – epascarello
@epascarello, 고맙습니다. 코드를 표시하기 위해 내 게시물을 업데이트했습니다. 나는 당신이 제공 할 수있는 어떤 도움에 대해서도 매우 감사 할 것입니다. – surfbird0713