Link to home
Create AccountLog in
Avatar of drbrahm
drbrahm

asked on

Modal Pop up Window Refreshing / Reloading Parent (opener) in Internet Explorer 7

Hey Folks,

I am able to open a modal pop up window in IE 7 but I am not figuring out how to reload / refresh the parent window (opener) from the  pop up one.

I am always getting an error like:

window.opener ou parent.opener is null and everything fails then.

in firefox it is working fine but IE 7.

I have checked here and there and all possible solutions  do not work for IE 7.

Notice: I am using window.showModalDialog to open the pop up window and I have assured the cache is empty in my testings.

Notice 2: I want do it WITHOUT close the child (pop up) window.
Any help is really appreciated !
Avatar of David H.H.Lee
David H.H.Lee
Flag of Malaysia image

Hi drbrahm,
Try this:

Page1.html
===============
<body onload="chk();">
<a href="javascript:void(0);" onclick="javascript:window.open('NPage.html')">Click!</a>
</body>

<script>
function chk(){
 alert('reload!');
}
</script>

NPage.html
=============
<script>
window.onload=function(){
 //reload parent page during onload event
  if (window.opener && window.opener.open && !window.opener.closed){
    window.opener.document.location.reload();
  }
}
</script>
please try to pass this to window.showModalDialog

var returnVal = window.showModalDialog('showModalDialog.html',this);

reload opener by
var openerwindow =window.dialogArguments;
      openerwindow.location.reload()


<script type="text/javascript">
var i=0;
function openModal(){
var returnVal = window.showModalDialog('showModalDialog.html',this);
alert("returnVal : " + returnVal);
}
</script>
<a href="javascript:;" onclick="openModal();">openModal()</a>
 
 
 
 
 
<html>
<head>
<title>Modal Dialog</title>
</head>
      <body >
            <a href="http://www.google.com"  onmousedown="window.returnValue = this.href;window.close();;">Click here</a>
            
            <a href="#" onclick="openerwindow.location.reload();">openerwindow.location.reload()</a>
      </body>
      
      <script type="text/javascript">
      var openerwindow =window.dialogArguments; 
      
      </script>
</html>

Open in new window

@fsze:
1. please always return false on onClick that does not change the current page
2. Why use BOTH onClick and onMouseDown? Why not JUST onClick?

@Asker: how can showModalDialog work in FF? It is not implemented there. You must have other code that DOES use the window.open and hence has a window.opener
What I mean is the following - however I wonder if the opener and the window in the dialog arguments disappears if the page is reloaded.

<script type="text/javascript">
function openModal(){
  var returnVal = window.showModalDialog('showModalDialog.html',window); // pass window, and not "this"
  alert("returnVal : " + returnVal);
  return false; // cancel the onClick
}
</script>
<a href="#" onclick="return openModal();">openModal()</a>
 
 
and in child page 
 
 
<html>
<head>
<title>Modal Dialog</title>
<script type="text/javascript">
var openerwindow = (window.dialogArguments)?window.dialogArguments:window.opener; 
</script>
</head>
<body >
<a href="http://www.google.com"  onClick="window.returnValue = this.href;window.close(); return false;">Click here</a>
<a href="#" onclick="openerwindow.location.reload(); return false">openerwindow.location.reload()</a>
</body>
</html>

Open in new window

mplungjan,
1) I according https://developer.mozilla.org/En/DOM/Window.showModalDialog  it works on ff3
2) why using onMouseDown? I don't want to change the current page.. on another way I can use return false; as you stated..
1: Okeee - that was surprising... So FF also has opener in showModalDialog?
yes, in child page. It having opener object, but not in ie6 ;)
Cool, i didn't know showModalDialog support in FF too.. Too bad for ie6 user (i'm part of them:-( ....)
What too bad?
It is only the opener object that is missing in IE6 (and 7 I would think)

Just pass the window in the dialogArguments and you are fine
yes passing window object to child page by window.dialogArguments is the critical
As you correctly mentioned in #23894995
Avatar of drbrahm
drbrahm

ASKER

hey guys,

both examples are working for FF but in IE 7 It is reloading the opener window only after pop up closes.. is it the expected ?

Thanks for all your help !
Modal=stop everything while we show the popup
ASKER CERTIFIED SOLUTION
Avatar of Kin Fat SZE
Kin Fat SZE
Flag of Hong Kong image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Avatar of drbrahm

ASKER

Thanks fsze88 ! It is a great workaround for me. keep your great posts  here!
Hmm, I think a tiny split was in order here, no?