JavaScript:window.confirm有两个窗口位置?

时间:2013-11-19 02:28:11

标签: javascript html ios

我正在使用登录系统创建HTML IOS应用程序。

当用户按下“退出”时,它会振动并弹出一个确认说“你确定要注销”有两个答案......确定和取消。

我想要转到index.html 但取消保持在同一页面(不退出)。

目前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>

1 个答案:

答案 0 :(得分:1)

使用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>