如何使一个函数只适用于第一个onload?

I have a classifieds website, and when users first enter the website a form is submitted on body onload event:

The form is submitted and displays its results in an iframe on the same page.

The problem is that I dont want the submit_form() function to be called everytime the user clicks back or forward in the browser, so how can I prevent the browser from submitting it when using back/forward buttons?

Example:

Form submits when user enters site.
Form shows Search Results in an iframe
User clicks one of the results and new page is displayed
User hits back button to go to the search results again
User finds the form has been resubmitted again, because of body onload triggers

How should I solve this?

Thanks

Client side only solution: Set a cookie.

you tagged this question with php so I think is better using server side session

  • start a session, init a session varto 0

Form submits when user enters site.

  • if session var == 0 then show results

Form shows Search Results in an iframe

  • set session var to 1

User clicks one of the results and new page is displayed User hits back button to go to the search results again

  • this doesn't happen:

User finds the form has been resubmitted again, because of body onload triggers