Solved

location.reload and post forms

Posted on 2004-08-05
20
52,552 Views
Last Modified: 2011-08-18
I have a dynamic site, where post data is often used.  Some of the site is available to those who are not logged in.  I do have a login button that opens up a login dialog window.  After they submit their loginid and password, a login processing page is loaded, and, assuming that the login was succesfull, a blank page comes up, which uses javascript to: 1) reload whatever page the person is on in the parent (main window) - ie self.opener.location.reload(true) ; and 2) Close itself - ie self.close().  Once the person is logged in they have additional options displayed to them.

The only problem is that if the person was on a page (in the main window) that had just received post data, the user gets a dialog thats says "The page cannot be refreshed without resending the information. Click Retry to send the information again, or click Cancel to return to the page that you were trying to view."  This is no good.  Is there anyway I can automatically force a resend of the information, or is there another javascript way of doing what I am trying to do?

Thanks in Advance,

:) David
0
Comment
Question by:dapperry
  • 9
  • 7
  • 3
  • +1
20 Comments
 
LVL 63

Expert Comment

by:Zvonko
ID: 11727283
Change this:
self.opener.location.reload(true)

To this:
self.opener.location=self.opener.location.href;

0
 
LVL 63

Expert Comment

by:Zvonko
ID: 11727323
If that does not reaload because of some caching, then append some random parameter for reload.
Like this:
<script>
if(self.opener.location.search){
   self.opener.location=self.opener.location.href+"&time="+(new Date()).getTime();
}else{
   self.opener.location=self.opener.location.href+"?time="+(new Date()).getTime();
}
self.close();
</script>

0
 
LVL 3

Author Comment

by:dapperry
ID: 11727505
The only problem with this method (self.opener.location=self.opener.location.href) is that it doesn't remember the form variables that were passed to it.  For instance I have one dynamic page that lists events for different cities.  It has a select box of major cities, that then does a form submit to itself, to display just the events for that city.  The default for the select is "All cities".  So if the person then selects Boston, the form is submitted to the page to only display the Boston events.  However, if the person then logs in, the page (using the above method) then reverts to "All cities" becuase the form variable is lost.  Is there anyway around this?

:) David
0
 
LVL 63

Expert Comment

by:Zvonko
ID: 11728209
Ok, then do a form submit.
Like this:

<script>
   self.opener.document.forms[0].submit();
   self.close();
</script>
0
 
LVL 4

Expert Comment

by:alikoank
ID: 11728467
>"The page cannot be refreshed without resending the information. Click Retry to send the information again, or click Cancel to return to the page that you were trying to view."

This is a security precaution. You should not be able to circumvent it.
0
 
LVL 63

Expert Comment

by:Zvonko
ID: 11728550
security??? It is a warning that the refresh will resend the data.
But in upper scenario should the form data be retained and new form content should be loaded from from server (reloaded)
So how would you fullfil both requirments: prevent entered data and load new content?
Of course by submitting the form. If that is a problem, then is the reload a wron strategy.
Loading one part of the page and let the rest as-is is possible only by reloading IFRAME embedded parts.
And of course with ActiveX scripting and with hidden frames.
0
 
LVL 3

Author Comment

by:dapperry
ID: 11728592
Ok, submitting the form might work.  However, sometimes I might have more than one form on a page, or might have none.  Can you tell me how I can get a listing of how many forms there are in the parent, and what the name fo each is?  If there is a way to do that, I think your solutions sounds like a good one.

:) David
0
 
LVL 63

Expert Comment

by:Zvonko
ID: 11728730
Hey stop. Why do you want to know how much forms? (you get that info from document.forms.length)
But before submitting any form you have to know what are you doing.
Anyway, when you have six forms on a page (what is bad design) and submit one, then are the entred data of the five other lost.

If you have complicated data on the page with several forms and want only to refresh a table on the page, then put that table in an iframe and reload that iframe.

0
 
LVL 3

Author Comment

by:dapperry
ID: 11728775
Actually, I do see one problem though.  I think if there was a listing of the forms, I would still need to check the action.  Certain forms submit to the same page as they are on, where others submit to a completely different page. So in a case where the form submitted to itself, doing a form submit would work.  However, what can be done about the form that submits to another page.  We don't want to submit the form, in that case, becuase that would bring us to the next page, and not the same page we are on.  For example, I have a three page survey.  After they fill out the first page, they submit a form to go to the second page.  Inside the second page their are hidden variables that hold the answers to page 1's questions, ans there are more questions.  Finally, the third page just processes the answers and displays a thank you message.  Now what if a person was on the second page when they logged in.  We don't want to lose the answers they recorded on the first page, but don't want to go to the processing page yet because they still need to answer the questions on page 2.  What do we do there?  I don't mind have a tree of logic here, as I want this thing to work through the entirety of the site.

:) David

0
 
LVL 3

Author Comment

by:dapperry
ID: 11728826
I don't have six forms on a page.  However, sometimes I have a select box to pick a city in one form (feeding itself), and another form that actually lets them register for the event (That one goes to another processing page)

:) David
0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
LVL 63

Expert Comment

by:Zvonko
ID: 11729011
Ok, let us start from the beginning.
You want at any public page on your server to allow Anonymous user to login.
Login is done in a popup window.
After successfull login you want the server to recognize at least the page from where the user opened the login popup to recognize that user is now logged in.
So what is your criteria to be logged in? I mean what server do you use and what scripting and what authentication method?
Why do you think will page reload help in login handling?
Do you want them to see authorized user options but not submit the data? That is nearly magic. I do not think that this is possible.

If you are realy crazy for this, then I have an idea how to do :)
Your popup should create an array of all forms on opener window and of all fields, checkboxes, radio buttons,select-multiple fields from every form, then reload the opener page by loading the actual opener URL and restore all values from the array and close itself.
Two problems in that scenario: after reloadin the opener, is the opener reference useless. Second: the popup cannot know when the opener finished reloading.

You see how crazy that is?
I would let the user retype the entered data.
If he want to be logged in, then he should decide that at the start of the procedure, or repeate the procedure if he forgot about that.


0
 
LVL 3

Author Comment

by:dapperry
ID: 11729576
Hi Zvonko,

I use Cold Fusion for the scripting (.cfm pages).  I don't know if you are familiar with Cold Fusion, but they have session variables.  When a person logs in certain session variables are set.  In each page (when the menu options are displayed) it checks for the existence of the session.userid variable.  If this variable is set (and other security levels are correct for the user) then the additional menu items are displayed in a left hand nav bar.  When a person logs off the session.userid var is cleared, and those menu options disappear.  I also have code on top of restricted pages that checks for existence of session.userid (and other security level options) before allowing the page to process.  If the person just trys to type in the url (when not logged in) they would be directed to a page that said that they weren't authorized to view the page in question, and to please login.

I guess you are right. I do want "them to see authorized user options but not submit the data?"  If they have taken the time to fill out the first page of the survey, I don't want to tell them that they have to start over, simply becuase they decided to login.  I just want them to see the page that they were on before logging in, in the same relative state as it was in before they logged in, except that they can now see the new authorized user options.

Do you think if I put the nav menu in an iframe that this might help?  While I have some experience with DHTML usings DIVS, I've never used IFRAMEs.  Let me know your best guess solution. Thanks for your help thus far.

:) David
0
 
LVL 63

Accepted Solution

by:
Zvonko earned 250 total points
ID: 11730596
If the only difference betwean Authenticated and Anonymous user pages the nav section is, then put that nav section in a separate page and show that nav page embedded in all pages where needed as <iframe name=nav src="nav.cf"></iframe>

And tell me please what that session.userid is.
Is that a hidden field in a form?
Or is that a solely server side variable?
0
 
LVL 3

Author Comment

by:dapperry
ID: 11730769
Hi Zvonko,
     Yes, the only difference is in the nav bar.  I will try putting the iframe tag in for a test.  How would I reference the iframe from the login dialog, so it could be reloaded without reloading the rest of the page. I mean can I do something like:

self.opener.iframe1.reload(true);

Yes, the session.userid is strictly a server side variable. Its not hidden in any forms.

:) David
0
 
LVL 63

Expert Comment

by:Zvonko
ID: 11730917
Your iframe needs a name.
I proposed in upper snippet the iframe name nav.
Then you could reload the iframe from the popup like this:

self.opener.frames.nav.location.reload(true);

0
 
LVL 6

Expert Comment

by:casstd
ID: 11760390
Hi,

         The solution for this warning page expired information is in the Microsoft website. Look at here.

http://www.experts-exchange.com/Web/Web_Languages/ASP/Q_21036164.html
0
 
LVL 6

Expert Comment

by:casstd
ID: 11760407
Hi,

           I found microsoft website has some Problem. The solution given in their website is use

<%Response.CacheControl="Public"%> in you page where you post form data. You will not encounter the Problem.

Hope this will help you.
0
 
LVL 6

Expert Comment

by:casstd
ID: 11768829
Hi,

         The microsoft link is ok now. http://support.microsoft.com/default.aspx?scid=kb;EN-US;183763
0
 
LVL 3

Author Comment

by:dapperry
ID: 11772951
Zvonko, it seems your idea about loading the nav bar into an iframe is going to work.  Thanks.

:) David

PS - casstd, I tried adding that cahce-control header, but it did not solve the problem.  I am worried about getting the resubmit dialog, not the page that says that its expired.
0
 
LVL 63

Expert Comment

by:Zvonko
ID: 11772982
Thanks for points and for the feedback.
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

When you need to keep track of a simple list of numbers or strings, the Array object is your most direct tool.  As we saw in my earlier EE Article (http://www.experts-exchange.com/A_3488.html), typical array handling might look like this: (CODE) B…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
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…

757 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

16 Experts available now in Live!

Get 1:1 Help Now