iframe popup refresh parent window not working in

2019-08-08 19:13发布

问题:

while in an iframe a user submits a popup window form.

the popup window closes and the parent window reloads redirecting user back to homepage.

here is the iframe code:

<iframe src="iframe.php"></iframe>

here is the popup inside the iframe:

function popupwnd(url, toolbar, menubar, locationbar, resize, scrollbars, statusbar, left, top, width, height)
{
   if (left == -1)
   {
      left = (screen.width/2)-(width/2);
   }
   if (top == -1)
   {
      top = (screen.height/2)-(height/2);
   }
var popupwindow = this.open(url, '', 'toolbar=' + toolbar + ',menubar=' + menubar + ',location=' + locationbar + ',scrollbars=' + scrollbars + ',resizable=' + resize +  ',status=' + statusbar + ',left=' + left + ',top=' + top + ',width=' + width + ',height=' +  height);
}

<a href="javascript:popupwnd()" target="_parent" title="Login into the Site">Login To Buy</a>

here is the javascript to close the poup window and redirect user to homepage:

<script>
    window.opener.location = /; 
    window.close();
</script>'; 

this process doesn't work in chrome or safari but does in IE and firefox.

回答1:

Using window.opener.parent.location.href instead of window.opener.location works in Chrome and Safari