PDA

View Full Version : Javascript browser back behavior


Lectrician
03-18-2009, 04:20 AM
I have a Perl script which creates a form.

This form is submitted to a PHP script which executes, plays with the code, and then automatically submits a hidden form itself back to my Perl script.

This means I have an 'empty' page inthe browsers history. If you click the back button you get the white page with "page expired". If you hit refresh the PHP script re-runs and causes issues as it uploads some files again.

Is there a way with javascript to force the page to be almost "invisible" if you like. If someone hits the back button and comes to this page, the page will cause them to jump back one page further?

Any info appreciated!

Lectrician
03-20-2009, 04:03 AM
Further to this, I have been googling.

I found this code:

<script type="text/javascript" language="JavaScript"><!--
function To(url) {
location.replace(url);
}
//--></script>


<a href="javascript:To('http://example.com/index.html')">Click Here!</a>


This code does hide the page where the URL link is placed when the browser back button is pressed.

I tried to use this same code by placing the "javascript:To" call as the form action URL.

This worked. The form is submitted, and the back button skips the previous page.

HOWEVER.....

No form elements make it through.

I am using the body onload command to auto submit the form which is created with purely hidden entries.

Hopefully someone can say if this code can be tweaked, or if I am barking!

rangana
03-20-2009, 05:18 AM
I'll pull the trigger and let you know that your goal wouldn't be done in the fashion that you've set your page up :disagree:

The replace() method wouldn't work too, as that only replaces the URL, but doesn't submits the form.

My thought was that you try to create an iframe (make it hidden), and give it a name of your desire, let's say for instance: myframe:

<iframe name="myframe" style="display:none;"></iframe>


...and add a target attribute to your form tag, pointing to the inline frame that you've recently created. Something along this lines should work:

<form target="myframe" ...


...what would happen is that your form will be submitted in the iframe, and of course, your page will never be redirected to a different URL.

Hope that makes sense.