doudu3961 2018-10-03 10:07
浏览 46

Cookies未在IE中读取

Im having a strange problem.

I have a subdomain where a customer comes in with a specific URL When the customer is recognized I set a cookie and redirect them to the main domain. there I check for this cookie to hide some elements. This is working great in Chrome, Firefox and even Edge on Microsoft, but not in IE11 and chrome on Apple machines.

When I type document.cookie in the IE console, I can see the cookie. I display a cookie found message in the console which I can see in chrome etc. but not in IE. So it looks like IE can't find the cookie, while it is actually there.

Is there someone who can explain this behaviour?

  • 写回答

1条回答 默认 最新

  • drq1257 2018-10-03 13:17
    关注

    I finally found the problem. When checking for the existence of the cookie, at first I used this line of jQuery code.

    if (document.cookie.split(';').filter((item) => item.includes('cookiename=')).length) {
    console.log('cookie found');
    }
    

    I briefly saw an error message in IE that pointed to this line of code.

    so, I changed it to the, btw much easier, line

    if (document.cookie.indexOf("cookiename=") != -1) {
     console.log('cookie found');
     }
    

    which IE has no problem with.

    评论

报告相同问题?

悬赏问题

  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用