0

From the parent page, I have opened a popup using window.open.

Then in the popup, I am trying to close the popup with window.close and on unload, trigger a click in the parent page.

Code in popup.aspx.cs:

ClientScript.RegisterStartupScript(typeof(Page), "closePage", "<script type='text/JavaScript'>window.close();</script>");

Code in the popup.aspx

<script type="text/javascript">
window.onunload = triggerclick;
function triggerclick()
{
var b = window.opener.document.getElementById('ctl00_PageContent_UpdateButton1');
b.click();
return false;
}
</script>

It works fine in FF and chrome, but not in IE 11. Any suggestions on how to tackle this issue? Thanks in advance.

lambda8
  • 317
  • 1
  • 4
  • 17

1 Answers1

0

Try window.onbeforeunload, not window.onunload.

benjarwar
  • 1,794
  • 1
  • 13
  • 28
  • I just tried this, doesnt work.. – lambda8 Aug 25 '15 at 13:05
  • All your test does is return a string, and it's probably doing just that. If you want to see the test, try putting ```alert('test');``` in your ```confirmExit``` function. ```window.onbeforeunload``` is definitely available in IE11. I just looked closer at your ```triggerclick``` function. You may not be able to fire events on elements in your window opener like that. See this question: http://stackoverflow.com/questions/18625733/how-do-i-get-around-window-opener-cross-domain-security – benjarwar Aug 25 '15 at 13:10
  • hmm, but it works fine in other browsers. I used alert('test') in the confirmExit function. It still does nothing. I always get this dialog box with this message: "The webpage you are viewing is trying to close the window. Do you want to close this window?" Once I click yes, the popup vanishes but alert doest work, it works fine in chrome and FF though. – lambda8 Aug 25 '15 at 13:27