0

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?

rdlgi
  • 1
  • 3
  • Is this all of your code? It seems like something is missing from your examples. – Adam Mar 21 '19 at 13:14
  • Try `$(w).find('#main').html(data);` – Teemu Mar 21 '19 at 13:16
  • Looks like you did not provided a detailed information regarding your issue. You need to check whether your Success function get called in IE or not. If it get called than what is the value of data parameter and which URL get passed? Try to check the console to see if there is any error or warning message is there. Set a break point in developer tools and try to debug the code step by step to check for the issue may help to narrow down the issue. You can inform your testing results to us. We will try to provide you further suggestions. – Deepak-MSFT Mar 22 '19 at 02:12
  • The Success function get's called because the new tab opens on the given url. I checked the console and it says "The object does not support the property or method "addEventListener"". If I run the code with `w.onload = function(){...}` instead of adding an event listener the console says nothing and It doesnt perform anything inside `function(){...}`. I also tried removing the event listener and the onload and just run `w.$('#main').html(data);` inside my success function then the console says "The object does not support the property or method "$"". The line of @Teemu is also not working. – rdlgi Mar 25 '19 at 09:19

1 Answers1

-1

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

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

rdlgi
  • 1
  • 3