Prevent Back button from showing POST confirmation alert
One way round it is to redirect the POST to a page which redirects to a GET - see Post/Redirect/Get on wikipedia.
Say your POST is 4K of form data. Presumably your server does something with that data rather than just displaying it once and throwing it away, such as saving it in a database. Keep doing that, or if it's a huge search form create a temporary copy of it in a database that gets purged after a few days or on a LRU basis when a space limit is used. Now create a representation of the data which can be accessed using GET. If it's temporary, generate an ID for it and use that as the URL; if it's a permanent set of data it probably has an ID or something that can be used for the URL. At the worst case, an algorithm like tiny url uses can collapse a big URL to a much smaller one. Redirect the POST to GET the representation of the data.
As a historical note, this technique was established practice in 1995.
Clicking the browser back button after getting the confirmation page
Step 1:
On the form submission page, initially set the form submission value to false.
sessionStorage.setItem('form-submit', false)
Step 2:
And when submitting the form in previous page, check:
function submitEvent() {
formSubmitted = sessionStorage.getItem('form-submit')
if (!formSubmitted){
// Write your code here
}
}
Step 3:
On confirmation.html
page, you can store a submission value in sessionStorage.
sessionStorage.setItem('form-submit', true)
Angular 2 - Prevent back button while REST API call is under processing?
You can set a property in your service, something like isDisabled = true, and create a directive that you can use anywhere, disabling your button and any other actions you might need.
Confirm browser back button else stay on page
You can't control the confirmation dialog button text, it's a hard coded feature of confirm()
and is whatever the browser has...not much you can do about it.
For the actual display you can use window.onbeforeunload
, but it won't be specific to the back button, any action leaving the page will trigger this, for example:
window.onbeforeunload = function() {
return "Are you sure you wish to leave this delightful page?";
}
Related Topics
Jquery Ui Sortable, Then Write Order into a Database
On Delete Cascade With Doctrine2
Magento - Quote/Order Product Item Attribute Based on User Input
Is Native PHP Support For Web Sockets Available
Best Way to Manage Long-running PHP Script
Insert String At Specified Position
Enabling Error Display in PHP Via Htaccess Only
Required Parameter $Xxx Follows Optional Parameter $Yyy
Is the Leading Colon For Parameter Names Passed to Pdostatement::Bindparam() Optional
How to Create Helper Methods on Laravel Not a Facade
Sorting a Multidimensional Array in PHP
Converting an Integer to a String in PHP
What Is the Best Collation to Use For MySQL With PHP
Create Programmatically a Woocommerce Product Variation With New Attribute Values
How to Remove Both .PHP and .Html Extensions from Url Using Nginx
How to Get the Content-type of a File in PHP
Woocommerce: Which Hook to Replace Deprecated "Woocommerce_Add_Order_Item_Meta"