phonegap + framework7 如何编程设置起始页?
phonegap + framework7 how to programmtacally set starting page?
我有一个应用程序,它在启动时让您选择 - 您是贡献者还是用户。之后,我希望始终为贡献者或用户加载起始页。我知道您可以将 <content src="index.html" />
设置为在开始时执行一次,但我如何动态地执行此操作?
你必须使用
localStorage
如果用户在首次启动后选择贡献者或用户按钮,则保存数据。
简单使用jQuery脚本:
<script>
$("#contributor").click( function()
{
//alert('button clicked');
localStorage.setItem("contributor", "contributor");
}
);
</script>
并调用相同的脚本,但用户为:
<script>
$("#user").click( function()
{
//alert('button clicked');
localStorage.setItem("user", "user");
}
);
</script>
如果用户之前按下 "user" 或 "contributor",那么在下一个 html 页面控件上。
$(document).ready(function() {
if (localStorage.getItem("user") === null) {
//user is null
} else {
document.location.href = "userIndex.html"
}
if (localStorage.getItem("contributor") === null) {
//contributor is null
} else {
document.location.href = "contributorIndex.html"
}
});
祝你好运!
@proofzy 回答是正确的,但你仍然可以只使用 DOM7 而不是 Jquery
在你的 JS 文件中:
//to save data if user pick contributor or user button after first start.
$$("#contributor").on('click', function(){
localStorage.setItem("whois", "contributor");
});
//And call this same script but for user:
$$("#user").on('click', function(){
localStorage.setItem("whois", "user");
});
//So call this function on the end of page index.html and it will redirect programmatically
function check(){
if (localStorage.getItem("whois") !== null) { //if whois exists on localStorage
if (localStorage.getItem("whois") == "user"){ // if is USER send to User Page
window.location.href = "userIndex.html"
}else if (localStorage.getItem("whois") == "contributor"){ // if is USER send to contributor Page
window.location.href = "contributorIndex.html"
}
}
}
还有很多其他方法可以做到,甚至更好,但这个是最简单的。
我有一个应用程序,它在启动时让您选择 - 您是贡献者还是用户。之后,我希望始终为贡献者或用户加载起始页。我知道您可以将 <content src="index.html" />
设置为在开始时执行一次,但我如何动态地执行此操作?
你必须使用
localStorage
如果用户在首次启动后选择贡献者或用户按钮,则保存数据。 简单使用jQuery脚本:
<script>
$("#contributor").click( function()
{
//alert('button clicked');
localStorage.setItem("contributor", "contributor");
}
);
</script>
并调用相同的脚本,但用户为:
<script>
$("#user").click( function()
{
//alert('button clicked');
localStorage.setItem("user", "user");
}
);
</script>
如果用户之前按下 "user" 或 "contributor",那么在下一个 html 页面控件上。
$(document).ready(function() {
if (localStorage.getItem("user") === null) {
//user is null
} else {
document.location.href = "userIndex.html"
}
if (localStorage.getItem("contributor") === null) {
//contributor is null
} else {
document.location.href = "contributorIndex.html"
}
});
祝你好运!
@proofzy 回答是正确的,但你仍然可以只使用 DOM7 而不是 Jquery
在你的 JS 文件中:
//to save data if user pick contributor or user button after first start.
$$("#contributor").on('click', function(){
localStorage.setItem("whois", "contributor");
});
//And call this same script but for user:
$$("#user").on('click', function(){
localStorage.setItem("whois", "user");
});
//So call this function on the end of page index.html and it will redirect programmatically
function check(){
if (localStorage.getItem("whois") !== null) { //if whois exists on localStorage
if (localStorage.getItem("whois") == "user"){ // if is USER send to User Page
window.location.href = "userIndex.html"
}else if (localStorage.getItem("whois") == "contributor"){ // if is USER send to contributor Page
window.location.href = "contributorIndex.html"
}
}
}
还有很多其他方法可以做到,甚至更好,但这个是最简单的。