jQuery 在 Internet Explorer 11 中不起作用

jQuery doesn't work in Internet Explorer 11

我的 ajax success:function() 运行 是打开新 window 并向其中插入数据的一行代码。现在我的代码看起来像这样:

success: function(data) {
  var url = location.href;
  var w = window.open(url);
  w.onload = function() {
    w.$('#main').html(data);
  };
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

它在 Chrome 中工作得很好,但如果我想在 Internet Explorer 11 中 运行 它不会执行 w.$('#main').html(data)。我也试过:

success: function(data) {
  var url = location.href;
  var w = window.open(url);
  w.addEventListener('load', function() {
    w.$('#main').html(data);
  }, {
    once: true
  });
}

这在 Chrome 中也能正常工作,但在 IE 中它给我的结果与上面的行相同。有人知道为什么这段代码在 IE 中不起作用吗?

我在这个帖子中找到了解决方案: addEventListener in Internet Explorer

我需要使用 attachEvent 方法而不是 addEventListeneronload