在通过registrybyId set href加载页面之前检查cookie值

check cookie value before loading page via registrybyId set href

本文关键字:检查 cookie 加载 registrybyId set href      更新时间:2023-09-26

我有一个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
        });
    }

登录成功后使用"dojo/cookie"设置cookie

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

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

ready(function () {
            var lia = cookie("LoggedInAs");
            alert(lia + " is logged in");
    });