JavaScript:window.conf,有两个窗口位置

JavaScript: window.confirm with two window locations?

本文关键字:两个 窗口 位置 window conf JavaScript      更新时间:2023-09-26

我正在创建一个带有登录系统的HTML IOS应用程序。

当用户按下"注销"时,它会振动,并弹出一个确认信息,说"你确定要注销吗",有两个答案。。。确定并取消。

我希望OK转到index.html但是CANCEL将停留在同一页面上(不注销)。

目前,Ok和Cancel都指向index.html(参见代码)

   function vibrate() {
        navigator.notification.vibrate(2000);
        window.confirm('Are you sure you want to log out?')
        window.location.href='index.html';
    }

我很感激的帮助

感谢

     <!DOCTYPE html>
  <html>
     <head>
    <meta charset="utf-8" />
    <meta name="format-detection" content="telephone=no" />
    <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1,  minimum-scale=1, width=device-width, height=device-height, target-densitydpi=device-dpi" />
    <link rel="stylesheet" type="text/css" href="css/index.css" />
            <script type="text/javascript" charset="utf-8" src="cordova.js"></script>
    <script type="text/javascript" charset="utf-8">
        document.addEventListener("deviceready", onDeviceReady, false);
        function onDeviceReady() {
        }
    </script>
    <script type="text/javascript" charset="utf-8">

        document.addEventListener("deviceready", onDeviceReady, false);
    function onDeviceReady() {
        }
function vibrate() { 
navigator.notification.vibrate(2000); 
navigator.notification.confirm('Are you sure you want to logout?',
     decide,
     'confirm logout?',
     ['cancel','ok'],
      );
        }
        function decide(button){
      if(button==2){
    window.location.href='index.html'; 
      }else{
         //Another stuff
      }     
  }
              </script>
          <title>Logged in</title>
      </head>
      <body>
          <h1>Welcome</h1>
  <p><a href="2index.html">Home</a></p>
  <p><a href="2courses.html">Courses</a></p>

  <input type="button" value="Log Out"onClick="vibrate();">
     </body>
  </html>

使用phonegap,您应该执行类似的操作

     <!DOCTYPE html>
  <html>
     <head>
    <meta charset="utf-8" />
    <meta name="format-detection" content="telephone=no" />
    <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1,  minimum-scale=1, width=device-width, height=device-height, target-densitydpi=device-dpi" />
    <link rel="stylesheet" type="text/css" href="css/index.css" />
            <script type="text/javascript" charset="utf-8" src="cordova.js"></script>

  <script>
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
}
function vibrate() { 
navigator.notification.vibrate(2000); 
navigator.notification.confirm('Are you sure you want to logout?',
     decide,
     'confirm logout?',
     ['cancel','ok']
      );
}

function decide(button){
      if(button==2){
        window.location.href='index.html'; 
      }else{
         //Another stuff
      }     
 }

              </script>
          <title>Logged in</title>
      </head>
      <body>
          <h1>Welcome</h1>
  <p><a href="2index.html">Home</a></p>
  <p><a href="2courses.html">Courses</a></p>

  <input type="button" value="Log Out"onClick="vibrate();">
     </body>
  </html>