代码之家  ›  专栏  ›  技术社区  ›  Theodorus Agum Gumilang

如何替换Cordova中的主页?

  •  0
  • Theodorus Agum Gumilang  · 技术社区  · 8 年前

    我做了登录功能,所以当用户登录时,它将导航到其他页面,但问题是登录成功后,用户只需按物理后退按钮即可再次返回登录页面。现在我想要的是,在登录后,用户无法再次返回登录页面,因此当按下物理后退按钮时,它将关闭应用程序。这是我的onloginsucces方法

    document.getElementById('auth').onclick = function () {
    $fh.auth({
      "policyId": "policyid",
      "clientToken": "appid",
      // Your App GUID
      "endRedirectUrl": window.location.href,
      "params": {
        "userId": document.getElementById('username').value,
        "password": document.getElementById('password').value
      }
    }, function(res) {
      // Authentication successful - store sessionToken in variable
      var sessionToken = res.sessionToken;
      alert("Login Succes");
      window.location = './menu.html';
    
    }, function(msg, err) {
      var errorMsg = err.message;
      if (errorMsg === "user_purge_data" || errorMsg === "device_purge_data") {
        // User or device has been black listed from administration console and all local data should be wiped
      } else {
        alert("Authentication failed - " + errorMsg);
      }
    })
    };
    

    除了使用窗口之外,还有其他方法吗。要导航的位置?就像窗户一样。也许可以替换,谢谢?

    更新

    <head>
        <meta charset="utf-8">
    
        <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    
        <title>Hello World</title>
    
        <link rel="stylesheet" href="css/app.css">
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
        <script type="text/javascript" src="cordova-2.7.0.js"></script>
        <script type="text/javascript" src="js/jquery.min.1.9.js"></script>
        <script type="text/javascript" src="js/jquery.mobile-1.3.1.min.js"></script>
    
        <script type="text/javascript">
            function onLoad() {
                document.addEventListener("deviceready", onDeviceReady, false);
            }
    
            // device APIs are available
            //
            function onDeviceReady() {
                // Register the event listener
                document.addEventListener("backbutton", onBackKeyDown, false);
            }
    
            // Handle the back button
            //
            function onBackKeyDown() {
                e.preventDefault();
            }
            </script>
      </head>
    
    1 回复  |  直到 8 年前
        1
  •  2
  •   Peter    8 年前

    请尝试以下操作:

    document.addEventListener("backbutton", onBackKeyDown, false);
       function onBackKeyDown(e) {
       #or return False
       e.preventDefault();
    }
    

    该功能禁用按钮功能。我从很久以前的一个页面上找到了这个 stackoverflow page . 我认为return False可以正常工作,但可能不是JS的正确用法。

    编辑感谢评论者:请注意,这需要在Cordovas on device ready listener中才能工作。