帝国cms会转义反斜杠即“\”,所以畅言代码在帝国cms里无法正常加载且前台会出现代码,
解决方法可以通过把js代码放入js文件,引入避免被转义。
也可以通过修改 window.document.write('<script id="changyan_mobile_js" charset="utf-8" type="text/javascript" src="https://changyan.sohu.com/upload/mobile/wap-js/changyan_mobile.js?client_id=' + appid + '&conf=' + conf + '"><\/script>');代码通过js创建script并引入https://changyan.sohu.com/upload/mobile/wap-js/changyan_mobile.js?client_id=' + appid + '&conf=' + conf 。具体改写成:
var oSohucs=document.getElementById('SOHUCS'); var b=document.createElement("script");b.setAttribute("id","changyan_mobile_js");b.setAttribute("type","text/javascript");b.setAttribute("charset","utf-8");b.setAttribute("src",'https://changyan.sohu.com/upload/mobile/wap-js/changyan_mobile.js?client_id=' + appid + '&conf=' + conf); oSohucs.parentNode.insertBefore(b,oSohucs.nextSibling);
则最终改写后的代码
<div id="SOHUCS" sid="[!--id--]" ></div> <script type="text/javascript"> (function(){ var appid = '您的畅言appid值'; var conf = '您的畅言conf值'; var width = window.innerWidth || document.documentElement.clientWidth; if (width < 960) { var oSohucs=document.getElementById('SOHUCS'); var b=document.createElement("script");b.setAttribute("id","changyan_mobile_js");b.setAttribute("type","text/javascript");b.setAttribute("charset","utf-8");b.setAttribute("src",'https://changyan.sohu.com/upload/mobile/wap-js/changyan_mobile.js?client_id=' + appid + '&conf=' + conf); oSohucs.parentNode.insertBefore(b,oSohucs.nextSibling); } else { var loadJs=function(d,a){var c=document.getElementsByTagName("head")[0]||document.head||document.documentElement;var b=document.createElement("script");b.setAttribute("type","text/javascript");b.setAttribute("charset","UTF-8");b.setAttribute("src",d);if(typeof a==="function"){if(window.attachEvent){b.onreadystatechange=function(){var e=b.readyState;if(e==="loaded"||e==="complete"){b.onreadystatechange=null;a()}}}else{b.onload=a}}c.appendChild(b)};loadJs("https://changyan.sohu.com/upload/changyan.js",function(){window.changyan.api.config({appid:appid,conf:conf})}); } })(); </script>
如果本文对你有帮助,欢迎打赏本站