简体   繁体   中英

jQuery doesn't work in Internet Explorer 11

My ajax success:function() runs a line of code which opens a new window and inserts data into it. Rigth now my code looks like this:

 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> 

It works just fine in Chrome but If I want to run it in Internet Explorer 11 it won't execute w.$('#main').html(data) . I also tried:

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

Which also works fine in Chrome but with IE it gives me the same result as the line above. Does anybody know why this code doesn't work in IE?

I found a solution in this thread: addEventListener in Internet Explorer

I need to use attachEvent method instead of addEventListener or onload .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM