0

我有一个 dijit 树,当单击一个节点时,它会在中心内容页面中加载一个 html 页面。其中一个 html 页面是登录页面,我想检查 cookie 以查看他们是否已经登录,因此如果页面重新加载,我可以适当地设置页面。有没有办法在页面加载时检查 cookie,或者比这更好的方法?谢谢

我的树代码是:

 TOCSet: function (TOCStore) {
        var myModel = new ObjectStoreModel({
            store: TOCStore,
            query: { root: true }
        });

        // Create the Tree.
        var tree = new Tree({
            model: myModel,
            onClick: function (item, node, evt) {
                // Get the URL from the item, and navigate to it
                evt.preventDefault();
                var href = item.url;
                registry.byId('Content').set('href', href); //set the page on node clicks
            }

        });
        tree.placeAt("TOC");
        tree.startup();
        ready(function () {
            registry.byId("Content").set("href", "Login.htm");//set the login page at start
        });

    }
4

1 回答 1

0

成功登录后,我使用“dojo/cookie”设置了 cookie

    function SetLoginCookie(lia) {
        cookie("LoggedInAs", lia);
    }

然后在页面重新加载时使用“dojo/ready”检查cookie

ready(function () {
            var lia = cookie("LoggedInAs");
            alert(lia + " is logged in");
    }); 
于 2014-07-24T18:16:39.597 回答