如何防止在某些页面上加载javascript代码?

时间:2012-10-12 19:29:45

标签: javascript janrain x-cart

我们使用电子商务平台X-cart来托管我们的购物车以及Janrain的内置集成,允许通过Facebook等进行社交登录。我们希望限制登录购物车页面的能力。 .js代码导致我们的网站在产品页面上加载缓慢。我们如何阻止.js代码在产品页面上运行?

1 个答案:

答案 0 :(得分:0)

只需将以下内容放在javascript文件的开头,导致速度缓慢:

if (window.location.href.indexOf('/path/to/shopping/cart/pages') != -1) {
   //We are in shopping cart pages
   //and we don't this js file to cause slowness, so just exit
   return;
}
// rest of the js file
...
相关问题