Window.open () returns undefined or null on the second call

I have the following script:

I click on the link that: opens a popup called "popup" that loads the PDF inside it (in IE6).

without closing the popup, I click the link again, which should open the PDF again inside the popup, but instead a javascript error occurs: the participant was not found

The javascript function used to open a popup:

function openWindow(url, name, props) { var windowRef = window.open(url, name, props); if (!windowRef.opener) { windowRef.opener = self; } windowRef.focus(); //error at this line, windowRef must be null return windowRef; } 

Question: how do I get around this without opening a new popup every time?

+4
source share
2 answers

This is a hack that works, which uses each of the Internet:

 function openWindow(url, name, props) { if(/*@ cc_on!@ */false){ //do this only in IE var windowRef = window.open("", name, props); windowRef.close(); } var windowRef = window.open(url, name, props); if (!windowRef.opener) { windowRef.opener = self; } windowRef.focus(); return windowRef; } 
+7
source

try using the global var windowRef outside the openWindow () function. Something like that:

 var WindowRef = null; function openWindow(url, name, props) { if(WindowRef == null){ WindowRef = window.open(url, name, props) } else{ WindowRef.document.location = url } if (!WindowRef.opener) { WindowRef.opener = self; } WindowRef.focus(); return WindowRef; } 
+4
source

Source: https://habr.com/ru/post/1285852/


All Articles