0

In the parent window, I have an onclick event that opens a (popup) child window (that contains a mp3 player, playing sample audio clips).

The child window is opened with:

<a href="#" onclick="popupwindow('popup.html', 'mp3Player',800,300 ); return false;">Mp3 Clips</a>

I assumed (wrongly;) I could return to the parent with:

<a href="#" onclick="window.opener();">return to win</a>

How do I return to the parent (& leaving the child window open).

In the parent window the javascript function is:

function popupwindow(url, winName, w, h) {
  var left = (screen.width/2)-(w/2);
  var top = (screen.height/2)-(h/2);
  return window.open(url, winName, 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=yes, copyhistory=no, width='+w+', height='+h+', top='+top+', left='+left);
} 
user801347
  • 1,165
  • 3
  • 14
  • 28
  • What do you mean "return to parent"? – Dexygen Nov 10 '18 at 00:38
  • I have a html page that displays in a browser 'window', it includes a link that opens a popup window (commonly referred to as a 'child' window). The original window is therefore commonly referred to as its 'parent' – user801347 Nov 10 '18 at 00:45
  • I have 19 years Javascript experience so I know all that, but what do you mean "*return* to parent"? – Dexygen Nov 10 '18 at 00:47
  • I want to display the original window. i.e. give it focus – user801347 Nov 10 '18 at 00:55
  • Possible duplicate of [window.opener.focus() doesn't work](https://stackoverflow.com/questions/18501095/window-opener-focus-doesnt-work) – Dexygen Nov 10 '18 at 00:59
  • Yes, thanks - possible duplication, but that was 5 yrs ago. I've found that 'window.opener.close()' closes the parent window. But 'window.opener.focus()' seems to do nothing. So I don't understand why it's a security issue, when closing another window isn't. Is there a solution? I'm testing in IE11, does it work in other browsers? – user801347 Nov 10 '18 at 01:09
  • whoops - I'm testing in Chrome not IE – user801347 Nov 10 '18 at 01:18
  • Just found that it DOES get focus in Safari – user801347 Nov 10 '18 at 01:21

1 Answers1

0

I could not get Chrome to focus the parent window, so (like the solution from 5yrs ago) for now have chosen to close the parent window, and re-open it with the original url (luckily I know which url is the parent).

onclick=('window,opener.close();window.open("https:www.....","_blank");return false;')

Thanks everyone for your help & guidance,

user801347
  • 1,165
  • 3
  • 14
  • 28