Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Reload parent window with parameters from within Javascript

Posted on 2006-04-26
10
Medium Priority
?
2,853 Views
Last Modified: 2008-02-01
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
0
Comment
Question by:ralphsauto
  • 4
  • 4
  • 2
10 Comments
 
LVL 29

Expert Comment

by:Pravin Asar
ID: 16546297
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
 
LVL 63

Expert Comment

by:Zvonko
ID: 16546503
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
 

Author Comment

by:ralphsauto
ID: 16546904
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

Author Comment

by:ralphsauto
ID: 16546915
No the parent doesn't need to be updated as the relevant information is stored in a cookie.
0
 
LVL 63

Accepted Solution

by:
Zvonko earned 2000 total points
ID: 16546979
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
 
LVL 29

Expert Comment

by:Pravin Asar
ID: 16547163
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
 

Author Comment

by:ralphsauto
ID: 16547689
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
 
LVL 63

Expert Comment

by:Zvonko
ID: 16548374
Try this:

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

0
 

Author Comment

by:ralphsauto
ID: 16548871
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
 
LVL 63

Expert Comment

by:Zvonko
ID: 16550769
Like this:

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



0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question