phonegap + framework7 how to programmtacally set starting page?

微笑、不失礼 提交于 2019-11-28 14:35:07

@proofzy answer is right, but you could still do it using only DOM7 instead of Jquery

Inside your JS file:

//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"
       }
   }
}

There are many other ways to do it, even better, but this one is simplest.

You must use

localStorage

to save data if user pick contributor or user button after first start. Simple use jQuery script:

<script>
    $("#contributor").click( function()
       {
       //alert('button clicked');
       localStorage.setItem("contributor", "contributor");
       }
    );
</script>

And call this same script but for user:

<script>
    $("#user").click( function()
       {
       //alert('button clicked');
       localStorage.setItem("user", "user");
       }
    );
</script>

So on next html page control if user is previously press "user" or "contributor".

    $(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"
       }
});

Good luck!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!