Solved

History.go(-1) not working if pop up window is opened

Posted on 2004-04-19
10
1,987 Views
Last Modified: 2011-09-20
I want to retain the user entered values by using history.go(-1). The following is the scenario

1. Main page is loaded (Contains code that instructs the browser to cache the page)
2. User enters the data in main page
3. Click submit button and this submits to a processing pae
4. In processing page, the data is insered to db
5. A Script is executed in process page...history.go(-1)
6. Main page is loaded again and previously entered values are retained.

I've a button in Main page. Onclick of the button will invoke a pop up window (Window name ABC, pop up page xyz.jsp). User will select some data in pop up page that will populate a field  (Using javascript)in Main page and will close the pop up window.

Now, if the user clicks submit button in Main Page, everything executes fine except that the Main Page is loaded again with BLANK data (USER ENTERED VALUES are not shown again even though I'm using history.go(-1))
 
Can this behavior of IE 6.0 be changed in anyway so that Main Page retains the values after submit using history.go(-1) (including the scenario where user visits pop up window) ?

I dont want to do major code change like using java beans or other mechanisms to retain Main page value. Thanks.
0
Comment
Question by:athuranand
10 Comments
 
LVL 33

Expert Comment

by:knightEknight
ID: 10863280
it is hard to tell without seeing your code ...
how are you opening the popup?
try setting the target of the form to the window name of the popup:

   window.open( "mypopup.jsp", "mypopup" );
   ...
   <form target="mypopup" ...
0
 
LVL 75

Accepted Solution

by:
Michel Plungjan earned 250 total points
ID: 10863306
Use cookies.
You cannot rely on go(-1)
0
 

Author Comment

by:athuranand
ID: 10863389
The following is the sample code

Main.jsp
   - Contains a button that will invoke Popu.jsp
   - On submit, invokes MyProcess.jsp
MyProcess.jsp
   - Contains a back button that will invoke history.go(-1)
Popup.jsp
   - This will populate a field in main page. Even a blank page wll do.

*******************************************************
Main.jsp(Main Page)
*******************************************************
<html>
<body>
<%
      response.setHeader("Cache-Control","public");
      response.setHeader("Pragma","cache");
      response.setDateHeader("Expires", 20160);
%>
<script>
function openWindow() {
      var popupWin=window.open('Popup.jsp','PopupPage','width=300,height=300,top=100,left=100');
      return true;
}
</script>
<form name="mytestform" method=post" action="MyProcess.jsp">
<input type="text" name="mytest" value="hello">
<input type="button" name="chooseme" value="open pop up window" onClick="openWindow();">
<br>
<input type="submit" value="Click Me" >
</form>
</body>
</html>
*******************************************************

MyProcess.jsp (Process Page)
*******************************************************
<html>
<body>
<form name="ProcessPage">
<input type="button" value="back" name="browserback" onclick="history.go(-1);">
</form
</body>
</html>

*******************************************************
Popup.jsp(Pop Up Page)
*******************************************************
<html>
<body>
<form action="xyz.jsp" name="mytest">
Welcome to pop-up
...
</form>
</body>
</html>

Hope this helps you to understand the issue
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 10863418
try this:


<form name="mytestform" method=post" action="MyProcess.jsp" target="myhidden">

.
.
<iframe height=1 width=1 name="myhidden" src="javascript:' '"></iframe>

Michel
0
 

Author Comment

by:athuranand
ID: 10863584
I forgot to add one information. Although I said I need solution in IE but our applications supports both IE 6.0 and Mozilla 1.6.  The sample code I've given works perfectly for Mozilla 1.6 but is not working in IE. I believe iframe solution wont work for Mozilla. Sorry about that.
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 10863629
Yes it will Mozilla and NS6+ understand iframes
0
 
LVL 63

Assisted Solution

by:Zvonko
Zvonko earned 250 total points
ID: 10863689
The regular way of doing that what you want to do is this:

Main.jsp(Main Page)
*******************************************************
<html>
<body>
<%
     response.setHeader("Cache-Control","public");
     response.setHeader("Pragma","cache");
     response.setDateHeader("Expires", 20160);
%>
<script>
function openWindow() {
     var popupWin=window.open('Popup.jsp','PopupPage','width=300,height=300,top=100,left=100');
     return true;
}
</script>
<form name="mytestform" method=post" action="MyProcess.jsp">
<input type="text" name="mytest" value="<%=mytest%>">
<input type="button" name="chooseme" value="open pop up window" onClick="openWindow();">
<br>
<input type="submit" value="Click Me" >
</form>
</body>
</html>
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
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…

744 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now