tags:

views:

434

answers:

2

Hi,

In my web application, I'm providing a link, clicking on which goes to another page, shows some data,popups a page and goes back using javascript back() function.

It was working fine but it fails in certain cases. For example, this link appears after a form submission also. When the back() function is called here, the Webpage Expired message is shown because it was a POST operation.

How can I go back to the previous page using javascript in this situation?

Please provide your inputs...

+1  A: 

You can't do anything about page expiration from JavaScript - that's how the browser opts to protect the user from re-submitting the form accidentally.

You could use the POST/Redirect/GET approach, depending on how your application works, to ensure users always land on a GET after submitting their form, so you always have a valid state to go back to.

To be honest, 99% of the time using the back() functionality in JavaScript is an indication something's wrong in the underlying approach. It's just too fraught with problems to be workable, as you're seeing here. You might get further if you start a new question to describe what you're trying to accomplish. There's a lot of really smart people around here who can all put their heads together and help you come up with something.

Rex M
A: 

Can you explain why you need to navigate to the previous page using client-side script? I'm assuming it's because the user may be arriving at this page from various other pages and you want to direct them back to the page they came from. You could always store the user's previous page URL in a session or cache object and direct them back to that URL in server-side code. Or, if you know where they will always be coming from, direct them back to a static URL. I may be able to offer more assistance if you offer more details.

jturn
Yes,the user may arrive from various other pages and I want to direct them back to their previous url. The page I'm editing is a part of portlet. So the header data will be already send by the time this portlet is executed. So I cant provide a server redirect by checking the referer.
whoopy_whale