亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

得到確認頁面后點擊瀏覽器返回按鈕

得到確認頁面后點擊瀏覽器返回按鈕

MM們 2022-10-18 16:12:48
我有一個頁面,我必須在其中填寫學生詳細信息,例如姓名、電子郵件和部門。一旦我填寫詳細信息并單擊submit my button它轉到下一頁,它會在下一頁中顯示輸入的學生詳細信息。在這里,我一步一步地展示了代碼。輸入詳細信息并單擊提交按鈕后的以下代碼。<div class="top-space-20">    <input class="btn btn-info" type="button" onclick="submitEvent()" class="btn" value="submit my details"></div>這是單擊提交我的詳細信息按鈕的腳本代碼。function submitEvent() {    form = document.createElement("form");    form.method = "POST";    form.action = "/confirmation";}單擊按鈕后,它會轉到后端并獲取一些詳細信息并顯示confirmation.html頁面。@app.route("/confirm",methods=['GET','POST'])def confirm():    "Confirming the event message"    response_value = request.args['value']    return render_template("confirmation.html", value=json.loads(response_value))@app.route("/confirmation", methods=['GET', 'POST'])def ssubmit_and_confirm():    "submit an event and display confirmation"    if request.method == 'POST':               return redirect(url_for('confirm', value=value))下面的代碼是confirmation.html頁面<body style="background-color:powderblue;">    <div class="panel panel-default" style="max-width:1000px;max-height: 800px;margin-left:auto;margin-right:auto;">        <div class="panel-heading " style="text-align: center;">submit student details</div>        <div class="panel-body" id="resultDiv">            <div class="panel-group">                <div class="panel panel-default">                    <div class="panel-body">                        <label class="col-md-8" for="Date:">Date:                            {{ value }}</br> Time :{{value}}</label>                        <label class="col-md-8" for="dateApplied"></label>                    </div>                </div>        </div>    </div></body>所以這里的問題是,一旦我進入confirmation.html,如果我點擊瀏覽器后退按鈕,它就會進入表單,它讓我可以添加相同的細節。但它不起作用。我嘗試了鏈接中給出的另一種方法 單擊后退按鈕后如何停止重新提交表單這也行不通。所以我需要的是,如果我點擊瀏覽器中的后退按鈕,我應該只顯示確認頁面,或者它應該告訴這不是授權頁面。
查看完整描述

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)


查看完整回答
反對 回復 2022-10-18
?
紫衣仙女

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

    };


}


查看完整回答
反對 回復 2022-10-18
?
慕田峪9158850

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")

   */

})


查看完整回答
反對 回復 2022-10-18
  • 3 回答
  • 0 關注
  • 174 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號