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 !
Web BrowsersJavaScript

Avatar of undefined
Last Comment
Michel Plungjan

8/22/2022 - Mon
David H.H.Lee

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>
Kin Fat SZE

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

Michel Plungjan

@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
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
Michel Plungjan

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

Kin Fat SZE

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..
Michel Plungjan

1: Okeee - that was surprising... So FF also has opener in showModalDialog?
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Kin Fat SZE

yes, in child page. It having opener object, but not in ie6 ;)
David H.H.Lee

Cool, i didn't know showModalDialog support in FF too.. Too bad for ie6 user (i'm part of them:-( ....)
Michel Plungjan

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
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
Kin Fat SZE

yes passing window object to child page by window.dialogArguments is the critical
Michel Plungjan

As you correctly mentioned in #23894995
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 !
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Michel Plungjan

Modal=stop everything while we show the popup
ASKER CERTIFIED SOLUTION
Kin Fat SZE

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
drbrahm

ASKER
Thanks fsze88 ! It is a great workaround for me. keep your great posts  here!
Michel Plungjan

Hmm, I think a tiny split was in order here, no?
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes