首页 > 解决方案 > Internet Explorer 引发错误并在以下行中退出处理:如何修复它?

问题描述

让 timerId = setInterval(() => { thisisanewguy = "true"; }, 1000);

 if (thisisanewguy != "true") {
                    if (popup == "false") {
                        if (cancelled2 != "true" && $('[id$=div_contactinfo]').length == 0 && $('[id$=div_specpopup]').length == 0 && $('[id$=familymold]').length == 0 && $('[id$=div_load]').length == 0 &&
                            $('[id$=painting]').length == 0 && $('[id$=printing]').length == 0 && $('[id$=customprocess]').length == 0 && $('[id$=insert]').length == 0 &&
                            $('[id$=assembly]').length == 0 && $('[id$=addpart2]').length == 0 && $('#div_background2').css("display") != "block" && $('#div_background').css("display") != "block" && $('#lightbox').css("display") == "none") {
                            setTimeout(function () {
                                if (!mouseEnter && cancelled2 != "true" && thisisanewguy != "true") {
                                    $('#alldone').css("display", "block");
                                    $('#div_background2').css("display", "block");
                                }
                            }, 5000);
                        }
                        else if ($('[id$=div_contactinfo]').length > 0) {
                            let timerId = setInterval(() => { thisisanewguy = "true"; }, 1000);
                            // after 10 seconds stop
                            setTimeout(() => { clearInterval(timerId); thisisanewguy = "false"; }, 10000);
                        }
                    }
                }

当然其他浏览器都可以。我们今天发现 IE 在这里下降了。而且我还没有弄清楚如何绕过它。我们 8% 的客户仍在使用 IE。

标签: internet-explorercross-browser

解决方案


我可以看到您在代码中使用了=>箭头函数,Internet Explorer 不支持该函数。

在此处输入图像描述

看这里...

在此处输入图像描述

参考:

箭头函数

要解决这个问题,您需要将代码从 ES6 转换为 ES5。

你可以使用Babel来编译你的代码。

这是使用 Babel 转译的代码示例。

"use strict";

if (thisisanewguy != "true") {
  if (popup == "false") {
    if (cancelled2 != "true" && $('[id$=div_contactinfo]').length == 0 && $('[id$=div_specpopup]').length == 0 && $('[id$=familymold]').length == 0 && $('[id$=div_load]').length == 0 && $('[id$=painting]').length == 0 && $('[id$=printing]').length == 0 && $('[id$=customprocess]').length == 0 && $('[id$=insert]').length == 0 && $('[id$=assembly]').length == 0 && $('[id$=addpart2]').length == 0 && $('#div_background2').css("display") != "block" && $('#div_background').css("display") != "block" && $('#lightbox').css("display") == "none") {
      setTimeout(function () {
        if (!mouseEnter && cancelled2 != "true" && thisisanewguy != "true") {
          $('#alldone').css("display", "block");
          $('#div_background2').css("display", "block");
        }
      }, 5000);
    } else if ($('[id$=div_contactinfo]').length > 0) {
      var timerId = setInterval(function () {
        thisisanewguy = "true";
      }, 1000); // after 10 seconds stop

      setTimeout(function () {
        clearInterval(timerId);
        thisisanewguy = "false";
      }, 10000);
    }
  }
}

推荐阅读