仅在移动设备中加载脚本不起作用

时间:2018-01-01 17:40:01

标签: javascript jquery cookies mobile

我找到了一个基于我的期望完美运行的脚本。它会检查是否存在特定的cookie并运行某些条件。直到这里,一切都还好:

$(document).ready(function(){
  if ($.cookie('bas_referral') == null ) {
      alert('There is no yet');
      console.log('setting cookie');
   var ref = document.referrer.toLowerCase();  
   // set cookie  
   var cookURL =  $.cookie('bas_referral', ref, { expires: 365 }); 
  } 
  else {alert('Now it has!')}; 
 });  

现在,我想以某种分辨率加载这个相同的脚本,但我写的代码不起作用。 = \

$(document).ready(function(){
if ($(window).width() < 767) {

  if ($.cookie('bas_referral') == null ) {
      alert('There is no yet');
      console.log('setting cookie');
   var ref = document.referrer.toLowerCase();  
   // set cookie  
   var cookURL =  $.cookie('bas_referral', ref, { expires: 365 }); 
  } 
  else {alert('Now it has!')};
}

else {alert('Large screen');} 
 });  

有谁知道为什么并可以帮助我?从现在开始,我感谢你! =]

1 个答案:

答案 0 :(得分:1)

  

if ($(window).width() < 767)

不是声明。 但是if ($(window).width() < 767)