Redirect to a page/URL after alert button is pressed

后端 未结 6 1165
没有蜡笔的小新
没有蜡笔的小新 2020-12-16 01:00

i have referred to this two questions call php page under Javascript function and Go to URL after OK button in alert is pressed. i want to redirect to my index.php after an

6条回答
  •  爱一瞬间的悲伤
    2020-12-16 01:12

    Like that, both of the sentences will be executed even before the page has finished loading.

    Here is your error, you are missing a ';' Change:

           echo 'alert("review your answer")'; 
           echo 'window.location= "index.php"';
    

    To:

           echo 'alert("review your answer");';
           echo 'window.location= "index.php";';
    

    Then a suggestion: You really should trigger that logic after some event. So, for instance:

               document.getElementById("myBtn").onclick=function(){
                     alert("review your answer");
                     window.location= "index.php";
               };
    

    Another suggestion, use jQuery

提交回复
热议问题