英文:
How hide javascript on specific page
问题
以下是您要翻译的内容:
我有一段用于我们应用程序在线聊天的 JavaScript 代码。但我需要使此代码不出现在特定页面上,例如 domain/X1XY。
请问您能告诉我如何在每个页面调用的主要代码中编写这个要求吗?
    <!-- Smartsupp Live Chat script -->
    <script type="text/javascript">
    var _smartsupp = _smartsupp || {};
    _smartsupp.key = '123456789';
    window.smartsupp||(function(d) {
      var s,c,o=smartsupp=function(){ o._.push(arguments)};o._=[];
      s=d.getElementsByTagName('script')[0];c=d.createElement('script');
      c.type='text/javascript';c.charset='utf-8';c.async=true;
      c.src='https://www.smartsuppchat.com/loader.js?';s.parentNode.insertBefore(c,s);
    })(document);
    </script>
英文:
I have a javascript code for our online chat that we use in our application. But I need this code to not appear on a specific page, eg domain/X1XY.
Can you advise me how I can write this in the main code that is called on each of our pages?
<!-- Smartsupp Live Chat script -->
<script type="text/javascript">
var _smartsupp = _smartsupp || {};
_smartsupp.key = '123456789';
window.smartsupp||(function(d) {
  var s,c,o=smartsupp=function(){ o._.push(arguments)};o._=[];
  s=d.getElementsByTagName('script')[0];c=d.createElement('script');
  c.type='text/javascript';c.charset='utf-8';c.async=true;
  c.src='https://www.smartsuppchat.com/loader.js?';s.parentNode.insertBefore(c,s);
})(document);
</script>
答案1
得分: 1
如果页面的URL是唯一的,那么你可以使用它来有条件地运行JavaScript,使用`document`对象的`URL`属性:
希望这有所帮助。
英文:
If the URL of the page is unique, then you can use it to conditionally run the JavaScript using the document object's URL property:
<script type="text/javascript">
	if (document.URL !== 'https://<your URL here>') {
		var _smartsupp = _smartsupp || {};
		_smartsupp.key = '123456789';
		window.smartsupp ||
			(function (d) {
				var s,
					c,
					o = (smartsupp = function () {
						o._.push(arguments);
					});
				o._ = [];
				s = d.getElementsByTagName('script')[0];
				c = d.createElement('script');
				c.type = 'text/javascript';
				c.charset = 'utf-8';
				c.async = true;
				c.src = 'https://www.smartsuppchat.com/loader.js?';
				s.parentNode.insertBefore(c, s);
			})(document);
	}
</script>
Hope this helps.
答案2
得分: 1
if (window.location.pathname !== '/X1XY') {
// your code here
}
英文:
if (window.location.pathname !== '/X1XY') {
// your code here
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。


评论