19 Kasım 2007 Pazartesi

Page Expire Problem When Browser's Back Button is Clicked

PROBLEM:

As a result of a search form submission, results are displayed as links. The user clicks any links and goes to that page. When back button is pressed, browser gives an error.


In detail,

1. User submits an HTML form that does a search.
2. User sees a list of search results, each hyperlinked to a details screen.
3. User clicks one of the "details" hyperlinks.
4. User sees the details screen.
5. User clicks browser's "Back" button to return to the screen in Step 2.
6. Browser gives confusing message about having to resubmit POST data. In Firefox this is a dialog box with OK/Cancel, and IE this is a white screen with the message:

"Warning: Page has Expired The page you requested was created using information you submitted in a form. This page is no longer available. As a security precaution, Internet Explorer does not automatically resubmit your information for you. To resubmit your information and view this Web page, click the Refresh button."

SOLUTION:

Handle the form inside javascript, and submit search using request parameters.

Not a Form, a text input field and a link:

SEARCH LINK
Javascript Code:function ProcessSearchSubmit() {
linkToRedirect="/search.ovt?results=allResults&searchInput=";
if ( document.getElementById('searchInputId') ) {
linkToRedirect += document.getElementById('searchInputId').value;
}
setTimeout( "window.location.href = linkToRedirect", 0 );
}

Window.location.href not working in IE for every page

There is a problem about javascript redirect in Internet Explorer. I couldn't redirect to another page in IE using

window.location.href = url;

This command gets executed (proofed with alert messages) but nothing happens. Firefox acts like expected but i couldn't get it work in IE.

I have finally found the solution after some google search.

RedirectUrl = url;
setTimeout( "window.location.href = RedirectUrl", 0 );

Another solution says that if you set this from the window.location.href in a Javascript function, is enough to return false. Check this out: IE bug.