gpt4 book ai didi

javascript - 如何更换 Cordova 主页?

转载 作者:行者123 更新时间:2023-12-01 02:11:19 25 4
gpt4 key购买 nike

我制作了登录功能,因此当用户登录时,它将导航到其他页面,但问题是登录成功后,用户只需按物理后退按钮即可再次返回登录页面。现在我想要的是登录后用户无法再次返回登录页面,因此当按下物理后退按钮时,它将关闭应用程序。这是我的 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);
}
})
};

除了使用 window.location 进行导航之外,还有什么方法吗?也许像 window.replace ,谢谢?

更新

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

最佳答案

尝试以下:

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

该函数禁用按钮功能。我从不久前在 stackoverflow page 上找到的页面中提取了此内容。 。我认为 return False 工作正常,但可能不是 JS 的正确用法。

感谢评论者的编辑:请注意,这需要在设备就绪监听器上的 Cordovas 中才能工作。

关于javascript - 如何更换 Cordova 主页?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49744687/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com