简体   繁体   English

子窗口关闭按钮

[英]Child window close button

This is my code. 这是我的代码。 When I click the close button on the child window it will display suresh on the screen but if I call popuponclick() function at the time itself suresh is getting displayed. 当我单击子窗口上的关闭按钮时,它将在屏幕上显示suresh,但是如果我在显示suresh时调用popuponclick()函数。 What I do?? 我所做的??

 popuponclick = function() { window.ChildWindow = window.open('GOLF12/shared/launchpage.html', 'popupWindow', 'width=700,height=700'); window.ChildWindow.attachEvent("onunload", OnChildWindowClose()); } OnChildWindowClose = function() { document.getElementById("my").innerHTML = "suresh"; window.ChildWindow = null; }; 

This will likely work better on your server 这可能会在您的服务器上更好地工作

It does not run if there is a popup blocker, then you will need to test if ChildWindow was opened correctly 如果有弹出窗口阻止程序,它将无法运行,那么您将需要测试ChildWindow是否正确打开

this fiddle works , but stacksnippets fail on the popup blocking 这种提琴奏效 ,但stacksnippets在弹出窗口阻止时失败

var ChildWindow;
function  popuponclick() {
  ChildWindow = window.open('GOLF12/shared/launchpage.html',
    'popupWindow',
    'width=700,height=700');
  setTimeout(function() { // we need to have the new page active
    ChildWindow.addEventListener("unload",OnChildWindowClose)
  },100)
}
function OnChildWindowClose() {
  this.opener.document.getElementById("my").innerHTML = "suresh";
  this.opener.ChildWindow = null;
};
<button onclick="popuponclick()">Click</button>
<span id="my"></span>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM