简体   繁体   中英

Go Back and resubmit form with javascript

I have added a back button to a search result page, with a link of:

<a href="javascript:window.location.reload(history.go(-1))">Back to seach results!</a>

But as this is being used with a form I am being met with a form resubmit page when using chrome, or an alert asking me to resubmit when using IE.

Is there and simple way to force the page to reload so the end user isn't met with either the screen or pop-up

Edit: I am using PHP so if there is a way of using PHP that would be okay too.

"No there's no way to prevent that alert. The reason is because the previous page was generated via a form submission, so to return to the page in that state the form submission has to occur again, hence the warning. The alternative would be to store the form parameters and have the back button resubmit the form manually"

Credit to Rory McCrossan

Yes there is a way. Add this to the page that has the 'Confirm Resubmit' popup

<script>
if(window.history.replaceState) { 
  window.history.replaceState( null, null, window.location.href ); 

}
</script>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM