JavaScript.CoolDev.Com Support Forums

Any questions related to JavaScript menu and JavaScript tree menu by Javascript.CoolDev.Com

 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Remembering a session id

 
Post new topic   Reply to topic    JavaScript.CoolDev.Com Forum Index -> COOLjsTree
Author Message
dmeysman



Joined: 07 Feb 2004
Posts: 14

PostPosted: Sat Feb 07, 2004 8:27 pm    Post subject: Remembering a session id Reply with quote

After a user logs into a system and begins to navigate a COOLjsTree tree,
what is the best way to remember a session id given to the user as he navigates different pages?
Back to top
AlexKunin
Developer


Joined: 03 Jan 2003
Posts: 1191

PostPosted: Sun Feb 08, 2004 8:36 am    Post subject: Reply with quote

In the other words, how to add something like "?sid=3fa08ed09cb" to every URL in tree_nodes.js automatically?
Back to top
dmeysman



Joined: 07 Feb 2004
Posts: 14

PostPosted: Sun Feb 08, 2004 3:04 pm    Post subject: Reply with quote

Yes, exactly.
Back to top
AlexKunin
Developer


Joined: 03 Jan 2003
Posts: 1191

PostPosted: Sun Feb 08, 2004 3:24 pm    Post subject: Reply with quote

Ok. Try this code:
Code:
var _TREE_NODES = [
   ['Search Engines', null, null,
      ['Google', 'http://www.google.com/', null],
      ['Lycos', 'http://www.lycos.com/', null],
      ['Yahoo!', 'http://www.yahoo.com/', null]
   ],
   ['Relative links', null, null,
      ['Link 1', 'test1.html', null],
      ['Link 2', '../test2.html', null],
      ['Link 3', '/test3.html', null]
   ]
];

function processLinks(nodes, variable, offset) {
   if (!offset)
      offset = 0;
   for (var i = offset; i < nodes.length; i++)
      if (nodes[i]) {
         if (nodes[i][1]) {
            var match = location.search.match(new RegExp(variable + '=[^&]*'));
            var url = nodes[i][1];
            if (match && !url.match(/^(http|https|mailto|ftp):/i))
               nodes[i][1] = url + (url.match(/\?/) ? '&' : '?') + match[0];
         }
         if (nodes[i][3])
            nodes[i] = processLinks(nodes[i], variable, 3);
      }   
   return nodes;   
}

var TREE_NODES = processLinks(_TREE_NODES, 'sid');
Back to top
Guest






PostPosted: Sun Feb 08, 2004 6:27 pm    Post subject: Reply with quote

Yes, thank you. I modified the processLinks() function to add the session id to the end of the url, and this is just what I needed.

if (nodes[i][1]) {
var url = nodes[i][1] + "?sid=" + variable;
nodes[i][1] = url;
}


I think very instructive and shows how a user can modify the TREE_NODES array to communicate with all the HTML pages it organizes.
Back to top
AlexKunin
Developer


Joined: 03 Jan 2003
Posts: 1191

PostPosted: Mon Feb 09, 2004 7:25 pm    Post subject: Reply with quote

Actually, original code did the same thing but in a smarter manner: it was merging GET queries, not just adding some text to the end of the URL. I.e. if input URL was my_page.php?sort=title, then output will be my_page.php?sort=title&sid=162536ef6ab64c.
Back to top
Guest






PostPosted: Wed Feb 11, 2004 2:58 am    Post subject: Reply with quote

I thought that might be the case.

I did try the original code right away, of course, but couldn't get it to work. Although my code change works for me, I'd encourage others to work with the original more closely. I'm not sure what I was doing wrong.

In any case, I appreciate your help on this.

David
Back to top
dmeysman



Joined: 07 Feb 2004
Posts: 14

PostPosted: Sat Jul 10, 2004 2:53 pm    Post subject: Doing the same in MENUPro Reply with quote

Is there a similar function to the one you suggested for adding the session id to every URL in a menu using menu_items.js?

That is adding something like "?sid=somesessionid" to each URL for each menu selection?

David
Back to top
AlexKunin
Developer


Joined: 03 Jan 2003
Posts: 1191

PostPosted: Thu Jul 22, 2004 3:19 pm    Post subject: Reply with quote

Look at the following post: http://javascript.cooldev.com/forum/viewtopic.php?t=785&highlight=addparameter.
Back to top
Display posts from previous:   
Post new topic   Reply to topic    JavaScript.CoolDev.Com Forum Index -> COOLjsTree All times are GMT
Page 1 of 1