Reload parent window with parameters from within Javascript

I have a minor problem that I am having issues with.  After a child window has been submitted I would like to have the parent window reload with parameters.  Is this possible?

This is an urgent matter so please also provide an example
ralphsautoAsked:
Who is Participating?
 
ZvonkoSystems architectCommented:
OK.
And for the onLoad question: no, it needs not to be in onLoad event handler. Every <script> is executed wherever it is located on the page.

0
 
Pravin AsarPrincipal Systems EngineerCommented:
Here is an example



parent.htm

<html>
<head>
<title>Parent Document</title>
</head>

<body>
<script language="javascript">
      window.open ("child.htm");
</script>
</body>
</html>

child.htm

<html>
<head>
<title>Child Document</title>
</head>

<body>
<form method="get" target="MyParent" action="parent.htm" onSubmit="window.opener.name='MyParent', window.setTimeout(function () { self.close(); }, 1000);"><input name="name" value="Default">
<input type="submit" name="submit">
</form>
</body>
</html>
0
 
ZvonkoSystems architectCommented:
Reloading the parent window on submit is easy as this:
<form name="yourForm" action="yourcgi.asp"  onSubmit="opener.location.reload(true)">


But that has a smal trap. Because you reload the parent on child form submit, is the server side not updated by the submit data and the reload of the parent does not reflect the submited state.
So the better choice is to do regular submit of the child form and responde this from your server page accepting the submit (I mean yourcgi.asp ):
<script>opener.location.reload(true);self.close();</script>

That two statements is all what the submit response need, and the parent will be refreshed and child closed, after the submit response arivel.

0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

 
ralphsautoAuthor Commented:
Both of you have good ideas, but first point is the child should not be closed as the submit is setting up for printing.  

Zvonko, I think that you have a better plan, simple is always good.  two things:

1: I already have a javascript page being loaded so I would use a reference to a function but thankfully no onsubmit function
2: The child window needs to submit the contents of the form then when it reloads the parent gets refreshed so maybe it should be  on the onload event?
0
 
ralphsautoAuthor Commented:
No the parent doesn't need to be updated as the relevant information is stored in a cookie.
0
 
Pravin AsarPrincipal Systems EngineerCommented:
My posted example assumed

1. You  do not want to have child form any more. Submitting the child to parent window and leaving the child window
   open may be confusing. As user is waiting for the current window to update.
2. If you do not want, do not close. It is upto you.
0
 
ralphsautoAuthor Commented:
Ok Zvonko your little script works the way I want it to except that it asks to repost the form data, can one cancel that so that it doesn't ask just reloads the page without the old form data?
0
 
ZvonkoSystems architectCommented:
Try this:

<script>opener.location.replace(opener.location.href)</script>

0
 
ralphsautoAuthor Commented:
How would I add Parmeters to the href even if I add it after a ?

is there a href = self?param1=56&param2=65

0
 
ZvonkoSystems architectCommented:
Like this:

<script>opener.location.replace(opener.location.href+((opener.location.search)?"&":"?")+"param3=33")</script>



0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.