0

Im trying to popup an information window in a specific interval. Its working fine when executing alone

var w = window.open('', "", "width=600, height=400, scrollbars=yes");
    //alert(ICJX_JXPath);
​
 var html = "<h3>Hi</h3>";
​
 $(w.document.body).html(html);

But if I execute the same in a timer function it triggers an error something like document is null

var myInterval = setInterval(function () {
            var w = window.open('', "", "width=600, height=400, scrollbars=yes");
    //alert(ICJX_JXPath);
​
 var html = "<h3>Hi</h3>";
​
 $(w.document.body).html(html);
        },10000);

Whats wrong with my timer code

Sandeep Thomas
  • 4,303
  • 14
  • 61
  • 132
  • document.body is accessible in the `setinterval` tag but the peoblem is actually with the returning window object w returning from `window.open` function. which is some times return null thats why i put null `if(w != null)` before the code and it works fine – Ahsam Aslam May 23 '19 at 06:02

1 Answers1

1

Your code is right but this code contains some unexpected text that actually hidden text. it shows in the browser source see the below screenshot: enter image description here

After edited that workable code here:

var myInterval = setInterval(function () {
    var w = window.open('', "", "width=600, height=400, scrollbars=yes");
    var html = "<h3>Hi</h3>";
    $(w.document.body).html(html);
},10000);

Above code not working directly in chrome fix the problem following code:

window.open('about:blank', "window", "width=600, height=400, scrollbars=yes");

-- Thank you --

Md. Abu Sayed
  • 2,396
  • 2
  • 18
  • 26