Open popup, click link, open in parent window, close popup?

泪湿孤枕 提交于 2019-12-10 17:27:06

问题


I need help please. What I want to do from my page is to open a popup for which I use this:

<a class="txt-button" onclick="javascript:void window.open('http://mypage.com/1/index.html','','width=700,height=500,resizable=false,left=0,top=0');return false;">Buy Now</a>

When a link on the popup is clicked I want it to open in the main window and for the popup to close.

I've tried many things and cant get it to work:-(


回答1:


I think you can use window.opener

window.opener.location.href=x



回答2:


To access main opener window from a pop-up use the window.opener object. You can access any opener property, or even a function call like that (as long as domains match, as @N Rohler pointed out in the comment to your question), for example to navigate use window.opener.location.href. Then you close your pop-up with window.close(); like this:

<a href="JavaScript:void(0);" onclick="openInParent('http://example.com/');">
  click me
</a>

<script>
  function openInParent(url) {
    window.opener.location.href = url;
    window.close();
  }
</script>


来源:https://stackoverflow.com/questions/14618972/open-popup-click-link-open-in-parent-window-close-popup

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!