How to refresh a parent frame from a pop up?

N

nicver

I am working on updating a Web site with a frameset. A page opens a
pop-up window in which the user uploads pictures. Once the upload is
done, I would like to refresh the content of the frame which opened the
pop-up but so far have failed. Here is my code:

<%

(ASP code which saves the photo in a database)

%>
<HTML>
<head>
<script language="javascript">
var url = top.parent.window.opener.document.all.MYURL.innerHTML +
'?ADID=<%=pintADID%>&MODE=S1&VIEWMODE=2';
top.parent.window.opener.location.href = url;
top.parent.window.close();
</script>
</head>
<body></body>
</html>


What I am trying to do is simply refresh the parent window with the
same URL. The ?ADID=<%=pintADID%>&MODE=S1&VIEWMODE=2' portion is there
to ensure that the browser does not refresh without the parameters.

Thanks a lot for your help!
 
R

Random

I am working on updating a Web site with a frameset. A page opens a
pop-up window in which the user uploads pictures. Once the upload is
done, I would like to refresh the content of the frame which opened the
pop-up but so far have failed. Here is my code: ....
var url = top.parent.window.opener.document.all.MYURL.innerHTML +
'?ADID=<%=pintADID%>&MODE=S1&VIEWMODE=2';
top.parent.window.opener.location.href = url;
top.parent.window.close();
....


Does the popup have a frameset?
If not, you could do this:

var url = (
opener.document.getElementById ?
opener.document.getElementById( 'MYURL' )
: opener.document.all.MYURL
).innerHTML + '?ADID=<%=pintADID%>&MODE=S1&VIEWMODE=2';

// if the location is already the url, just reload
if( opener.location.href == url )
opener.location.reload();

// otherwise, nagivate to said url
else
opener.location.href = url;

window.close();
</script>
</head>
<body></body>
</html>


What I am trying to do is simply refresh the parent window with the
same URL. The ?ADID=<%=pintADID%>&MODE=S1&VIEWMODE=2' portion is there
to ensure that the browser does not refresh without the parameters.

See above.

The code above is missing some compatibility checks for brevity's sake.

Also, in some circumstances it is a bad a idea to print the URL into
the page without first doing some translation of it. I don't know how
you're putting the URL in the page itself (i.e. whether you're building
the URL from scratch, doing any translation, or just dumping it into
the output), but be aware of any possible security considerations, as
this will allow users to essentially edit the code of the page that is
displayed and cause the browser to interpret the code in the context of
your domain name.

You may also want to check that the parent window is still relevant to
the popup, prior to trying to work with it.
 
N

Nicolas Verhaeghe

Thanks. I am only taking over some sloppy development done prior to me. The
job is to get something to work, without reprogramming everything. The
client already spent a fortune for a Web site which does not function
properly.

I am not the best Javascript programmer out there, because I never really
spent a lot of time learning the compatibility issues.

Is this code MSIE-only? What would also work with Mozilla/Firefox and
Safari?

Thanks a lot for your help!
 
R

Random

So far as I know it should work in most relatively modern browsers.
Expect compatibility issues with older versions of Netscape that few
people still use, and probably other older, less-used agents.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,780
Messages
2,569,610
Members
45,254
Latest member
Top Crypto TwitterChannel

Latest Threads

Top