3 回答

TA貢獻1836條經驗 獲得超3個贊
第一步:在表單提交頁面,初始設置表單提交值為false。
sessionStorage.setItem('form-submit', false)
第2步:在上一頁提交表單時,檢查:
function submitEvent() {
formSubmitted = sessionStorage.getItem('form-submit')
if (!formSubmitted){
// Write your code here
}
}
第 3 步:在confirmation.html頁面上,您可以在 sessionStorage 中存儲提交值。
sessionStorage.setItem('form-submit', true)

TA貢獻1839條經驗 獲得超15個贊
存儲表單數據并在表單數據發送到服務器之前重置表單。假設您使用 $.ajax() 提交表單。
function submitEvent() {
form = document.createElement("form");
form.method = "POST";
form.action = "/confirmation";
// Add id attribute to the form
form.id = "student_details_form";
// Collect form data
// reset your form just before calling $.ajax() or $.post()
document.getElementById('student_details_form').reset();
// call $.ajax() or $.post()
$.ajax({
url: form.action,
// snipps
};
}

TA貢獻1794條經驗 獲得超7個贊
您可以添加 HTML5 歷史 API。使用以下代碼。
name = document.title
history.pushState(null,name,name)//add this code in your configuration.html file in document ready block
$(window).on("popstate",()=>{
//....Do whatever you want
/*If you want to display unauthorized page then
$(document).html("Unauthorized page")
*/
})
添加回答
舉報