You have to attach a DOMNodeInserted-listener before the click event is fired, then you can access this window-object.
// assuming that all inserted alements are links or a-tags
// this code must run before the code that adds the a-element
document.addEventListener("DOMNodeInserted", function (ev) {
var link = ev.target;
var oldRef = link.href;
link.onclick = function(event){
event.preventDefault();
var childWindow = window.open(oldRef);
childWindow.onload = function(){
console.log('at this point you can interact with this newly opened window-object: ',childWindow);
};
};
});
//...
// some other code
//...
var p = document.getElementById("myElement");
var a = document.createElement('a');
a.setAttribute('href',".../mypage.html");
a.setAttribute('rel',"noreferrer");
a.setAttribute('target',"_blank");
p.appendChild(a);
a.click();
Hope this helps.