Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

How do I pass a variable like username between two jQueryMobile pages?

or two regular pages for that matter, having the variable as global does not work, since at the next include it will set the variable back to null.

How do I pass a variable a global variable between two html pages?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
260 views
Welcome To Ask or Share your Answers For Others

1 Answer

I usually go with local storage, you can store objects too. Ex:

var userInfo = {
            "username": "Bob",
            "roleName": "Admin",
            "image": "img/userPic.jpg",
        };

        //Store the object in local storage
        localStorage.setItem('loggedUser', JSON.stringify(userInfo));

then on the other page you can simply do:

var userInfo = JSON.parse(localStorage.getItem("loggedUser"));
var userName = userInfo.username;

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...