如何在特定页面上隐藏JavaScript

huangapple go评论65阅读模式
英文:

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?

&lt;!-- Smartsupp Live Chat script --&gt;
&lt;script type=&quot;text/javascript&quot;&gt;
var _smartsupp = _smartsupp || {};
_smartsupp.key = &#39;123456789&#39;;
window.smartsupp||(function(d) {
  var s,c,o=smartsupp=function(){ o._.push(arguments)};o._=[];
  s=d.getElementsByTagName(&#39;script&#39;)[0];c=d.createElement(&#39;script&#39;);
  c.type=&#39;text/javascript&#39;;c.charset=&#39;utf-8&#39;;c.async=true;
  c.src=&#39;https://www.smartsuppchat.com/loader.js?&#39;;s.parentNode.insertBefore(c,s);
})(document);
&lt;/script&gt;

答案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:

&lt;script type=&quot;text/javascript&quot;&gt;
	if (document.URL !== &#39;https://&lt;your URL here&gt;&#39;) {
		var _smartsupp = _smartsupp || {};
		_smartsupp.key = &#39;123456789&#39;;
		window.smartsupp ||
			(function (d) {
				var s,
					c,
					o = (smartsupp = function () {
						o._.push(arguments);
					});
				o._ = [];
				s = d.getElementsByTagName(&#39;script&#39;)[0];
				c = d.createElement(&#39;script&#39;);
				c.type = &#39;text/javascript&#39;;
				c.charset = &#39;utf-8&#39;;
				c.async = true;
				c.src = &#39;https://www.smartsuppchat.com/loader.js?&#39;;
				s.parentNode.insertBefore(c, s);
			})(document);
	}
&lt;/script&gt;

Hope this helps.

答案2

得分: 1

if (window.location.pathname !== '/X1XY') {
// your code here
}

英文:

if (window.location.pathname !== &#39;/X1XY&#39;) {
// your code here
}

huangapple
  • 本文由 发表于 2023年2月19日 00:15:47
  • 转载请务必保留本文链接:https://go.coder-hub.com/75494649.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定