Snitz Forums 2000
Snitz Forums 2000
Home | Profile | Register | Active Topics | Members | Search | FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 Help Groups for Snitz Forums 2000 Users
 Help: General / Current Version (Old)
 URGENT Cookie Question
 New Topic  Topic Locked
 Printer Friendly
Author Previous Topic Topic Next Topic  

Deleted
deleted

4116 Posts

Posted - 03 August 2001 :  12:23:32  Show Profile
I never played before with JS cookies, and I cannot say that I'm good in JS. I surfed Internet on ASP&JS cookies but couldn't find answers to my questions.

What I'm trying to do is to use mixed serverside VB-ASP and clientside JS use the same cookies. Is this possible? In the ASP cookie collections it has the "key" parameter, but in JS documents speak of "pairs". So, how do I reproduce the effect of


Response.Cookies(strUniqueID & "User")("LANG") = strLangPrefCode


with client side JS? The following JS code


document.cookie = strUniqueID + "User (LANG)=" + langcode;

actually I let ASP write this as:

response.write "document.cookie = """ & strUniqueID & "User (LANG)="" + langcode;" & vbCrLf



could not be read back through


LangReadCookie = Request.Cookies(strUniqueID & "User")("LANG")


Perhaps I'm totally mistakin. Any help will be very much appreciated.


Think Pink

Deleted
deleted

4116 Posts

Posted - 03 August 2001 :  12:46:06  Show Profile
quote:


document.cookie = strUniqueID + "User (LANG)=" + langcode;




For sure the above code is completely wrong . The cookie debug shows:

Snitz00User=NAME=admin&PWORD=admin&COOKIES=

So, do I have to read the cookie in JS and write it back after appending new value?

Think Pink
Go to Top of Page

Davio
Development Team Member

Jamaica
12217 Posts

Posted - 03 August 2001 :  14:21:43  Show Profile
Well, I'll tell you what I know about cookies, between ASP and JS.

I think javascript writes cookies differently than ASP does. I mean, you can create cookies with different keys in ASP, like

Response.Cookies(strUniqueID, & "User")("Name") = "admin"
Response.Cookies(strUniqueID, & "User")("Pword") = "admin"


But the javascript alternative is something like this:

var curCookie = "User=Name:admin&Pword:admin";
document.cookie = curCookie;


I also learnt that you can retrieve cookie info from a cookie that was created by javascript using ASP, but you can't write to that cookie using ASP. You can only write to a javascript created cookie using javascript.

- David

Edited by - Davio on 03 August 2001 14:23:13
Go to Top of Page

Doug G
Support Moderator

USA
6493 Posts

Posted - 03 August 2001 :  14:26:08  Show Profile
Never did much with client-side cookies, but here are a couple links I found.

http://www.webreference.com/js/column8/
http://www.echoecho.com/jscookies.htm


======
Doug G
======
Go to Top of Page

Deleted
deleted

4116 Posts

Posted - 03 August 2001 :  14:58:43  Show Profile
Thank you for answering.

quote:

var curCookie = "User=Name:admin&Pword:admin";
document.cookie = curCookie;




This exactly I recognized and mentioned in my second post.

quote:

I also learnt that you can retrieve cookie info from a cookie that was created by javascript using ASP, but you can't write to that cookie using ASP. You can only write to a javascript created cookie using javascript.



Sorry, but I don't think this is true. Do you have a link for this info?. Perhaps there is no direct way (if you use the key concept ASP uses). It's exacly the same "data" but the interpreters are different. So, I think if I get the whole cookie using JS, parse it, replace the related part, and put back using JS, it must be OK.

It's ofcourse very cumbersome work but I think it can be done. I have to open my online JS reference :).

What I'm trying to do is to keep the user selected language (from a drop down list) in the cookie. This will be done using "JS onchange". After reload, ASP will get this info from the cookie to show the page in the correct language. I know that this can be done using request.form, but to make the user selection also valid in other pages (non-forum pages or forum pages that do not use the config asp) I prefer the cookie.

What do you think?


Think Pink
Go to Top of Page

Deleted
deleted

4116 Posts

Posted - 03 August 2001 :  20:42:08  Show Profile
Well, its not completely tested, but the following code works fine. Any žnput from JS experts are welcome.


<SCRIPT LANGUAGE="JavaScript">
<!--
function LangReload(form) {
var resstr;
var snitzcookie;
var newsnitzcookie;
var snitzcookietag = "Snitz00User";
var langcode = form.LanguageSelector.options[form.LanguageSelector.selectedIndex].value;
var cookie_string = "" + document.cookie;
var cookiefound = cookie_string.indexOf(snitzcookietag);
if (cookiefound == -1) // snitzcookie not found
{ resstr = snitzcookietag + "=LANG=" + langcode }
else { // cookie found, so extract it
snitzcookie= cookie_string.substring(cookiefound,cookie_string.indexOf(";",cookiefound+1));
snitzcookie= cookie_string.substring(cookiefound,cookie_string.indexOf(";",cookiefound+1));
var langfound = snitzcookie.indexOf("LANG=");
if (langfound == -1) // langtag not found
{ newsnitzcookie = snitzcookie + "&" + "LANG=" + langcode }
else { // lang tag found, so change it
var re= /LANG=../;
newsnitzcookie= snitzcookie.replace(re,"LANG=" + langcode) ;
}
resstr = cookie_string.replace(snitzcookie,newsnitzcookie);
}
document.cookie = resstr;
location.href = location.href;
return false;
}
// -->
</SCRIPT>



Think Pink
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Topic Locked
 Printer Friendly
Jump To:
Snitz Forums 2000 © 2000-2021 Snitz™ Communications Go To Top Of Page
This page was generated in 0.33 seconds. Powered By: Snitz Forums 2000 Version 3.4.07