| Author |
Message |
dmeysman
Joined: 07 Feb 2004 Posts: 14
|
Posted: Sat Feb 07, 2004 8:27 pm Post subject: Remembering a session id |
|
|
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
|
Posted: Sun Feb 08, 2004 8:36 am Post subject: |
|
|
| 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
|
Posted: Sun Feb 08, 2004 3:04 pm Post subject: |
|
|
| Yes, exactly. |
|
| Back to top |
|
 |
AlexKunin Developer
Joined: 03 Jan 2003 Posts: 1191
|
Posted: Sun Feb 08, 2004 3:24 pm Post subject: |
|
|
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
|
Posted: Sun Feb 08, 2004 6:27 pm Post subject: |
|
|
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
|
Posted: Mon Feb 09, 2004 7:25 pm Post subject: |
|
|
| 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
|
Posted: Wed Feb 11, 2004 2:58 am Post subject: |
|
|
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
|
Posted: Sat Jul 10, 2004 2:53 pm Post subject: Doing the same in MENUPro |
|
|
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
|
|
| Back to top |
|
 |
|