-
I need to set a cookie for a web page I'm making to memorize a users login/pass and also the ColWidth property of an ActiveX grid I have on the page. Do I need a CGI server running on my computer? (I'm hosting the page locally) Also, how do I put the ColWidth property into the cookies, since I'll presumably be using JavaScript to create the cookie but the ColWidth is part of an ActiveX control which only VBScript can access. Could I create some sort of global variable that vbscript can put the colwidth property in and then jscript can access it? Thanks!
-
the ColWidth is part of an ActiveX control which only VBScript can access.
Who said javascript can't access Activex Controls ?
Which world are you from ?
Anything that has an ID can be accessed in IE....
That can be done in Javascript,Jscript, and Vbscript.
Try this now...
Code:
<script Language="javascript">
function getColWidth(){
var hold = mygrid.ColWidth ;
setcookie("Colwidth",hold);
//this is your own function to achieve that..
}
</script>
<body background="/images/bground.gif" bgcolor="#ffffff" text="#000000" marginheight="0" topmargin="0">
<object ID="mygrid" .....
...................</object>
(use Activex control pad for this)
</Body>
-
Hey Don't Get Confused by the
background="/images/bground.gif ....stuff in the body tag.
Infact I did not add that..I just put a <body> tag there and vbworld forum page generator got confused with that..
Nothing significant about that...
If You want the Cookie Javascript code...
Here is one big code..Save it as a js file and refer it from the script tag..
Code:
/* COOKIES.JS - JavaScript Cookies Library (version 1.2)
** =====================================================
**
** This JS library contains OOPed versions of the standard set of
** JS cookie functions: store, get, and del. You may use and/or
** modify this code *if* you maintain this copyright header.
**
** 2000, Richard Scott (version 1.2)
** Added duration constants and getExpirationDate() to help set
** cookie expiration dates. Beefed up comments a bit.
**
** 1999, Richard Scott (version 1.1)
** Streamlined Cookie(), Cookie_store(), Cookie_get(), Cookie_del().
** Removed document parameter from Cookie() constructor function.
** Removed CookieTable() diagnostic tool. Added explanatory comments.
**
** Copyright 1997, Christopher Doemel (version 1.0). All rights reserved.
** There are several good JavaScript cookie libraries around.
** One is Bill Dortch's public domain cookie functions
** (at http://www.hidaho.com/cookies/cookie.txt), and another is David
** Flanagan's cookie example in JavaScript: The Definitive Guide,
** published by O'Reilly Press. This library combines the best features
** of both: The thoroughness of Dortch's cookie functions, and the
** object-oriented design of Flanagan's cookie example.
*/
/* JavaScript Cookies Library Usage
** ================================
** To create a Cookie object:
** cookieName = new Cookie(name[,expires][,domain][,path][,isSecure]);
** (Cookie() arguments are described below)
** To retrieve data from a cookie:
** cookieData = cookieName.get();
** To store data in a cookie:
** cookieData = "Hi there!";
** cookieName.store(cookieData);
** To delete a cookie:
** cookieName.del();
**
** You must create a Cookie object *before* you attempt to access
** (retrieve/store/delete) the cookie. This is true for both new
** and old (existing) cookies.
** To create a new cookie named "newCookie" (with an expiration
** (date of 12/1/2000) and store data in it:
** newCookie = new Cookie("newCookie", new Date(2000,11,1));
** newCookie.store("Hello World!");
** To read the contents of an existing cookie named "oldCookie":
** oldCookie = new Cookie("oldCookie");
** cookieData = oldCookie.get();
** To delete an existing cookie named "anotherCookie":
** anotherCookie = new Cookie("anotherCookie");
** anotherCookie.del();
*/
/* Duration Constants */
/* ================== */
/* used in conjunction with getExpirationDate(), these */
/* simplify the task of getting a cookie expiration date */
var MSECSINSECOND = 1000;
var MSECSINMINUTE = 1000 * 60;
var MSECSINHOUR = 1000 * 60 * 60;
var MSECSINDAY = 1000 * 60 * 60 * 24;
var MSECSINWEEK = Math.round(1000 * 60 * 60 * 24 * (365.25/52));
var MSECSINMONTH = Math.round(1000 * 60 * 60 * 24 * (365.25/12));
var MSECSINYEAR = Math.round(1000 * 60 * 60 * 24 * 365.25);
var MSECSINDECADE = Math.round(1000 * 60 * 60 * 24 * 365.25 * 10);
/* getExpirationDate(duration) */
/* =========================== */
/* returns a date object to use for the expires arg to new Cookie() */
/* duration - time (in msecs) from now to set expiration date */
/* to get an expiration date = one week from now, you'd code: */
/* var expirationDate = getExpirationDate(MSECSINWEEK) */
/* to get an expiration date = a decade from now, you'd code: */
/* var expirationDate = getExpirationDate(MSECSINDECADE) */
/* to get a cookie to expire after the current session, simply */
/* leave out the new Cookie() expires arg */
function getExpirationDate(durationInMsecs)
{
var today = new Date(); // get today's date
today = today.getTime(); // convert it to milliseconds
today = today + durationInMsecs; // add durationInMsecs to it
today = new Date(today); // convert it back to a date
return today; // and, finally, return it
}
/* Cookie()
** ========
** The Cookie constructor function takes the following arguments:
** name (required) The name of the name/value pair stored in the cookie.
** expires (optional) A date object specifying the lifetime of the cookie.
** After the date specified, the browser stops storing the
** cookie. If no date is specified, the cookie will be
** lost when the browser quits.
** domain (optional) If a page's URL matches this domain, the browser will
** make the cookie available. For instance, if the cookie
** domain is set to "palimpsest.com," "tabula.palimpsest.com"
** is eligible to receive the cookie. The page's URL is
** also matched against the cookie's path (described below).
** The default domain is the domain of the document that
** creates the cookie.
** path (optional) Specifies the subset of URLs that will receive the
** cookie. The default value is the path of the document
** that creates the cookie.
** isSecure (optional) If the cookie is secure, it will only be transmitted
** over secure channels (i.e., to pages sent via HTTPS
** servers). The default value is false.
*/
function Cookie(name, expires, domain, path, isSecure)
{
this.name = name;
this.expires = expires;
this.domain = domain;
this.path = path;
this.isSecure = isSecure;
if (this.expires) // adjust cookie date to fix Mac Netscape 2.x bug
fixCookieDate(this.expires);
}
/* fixCookieDate()
** ===============
** Internal function that corrects for the Macintosh Netscape 2.x date bug.
** This function is only called by the Cookie() constructor. The fix works
** by creating a Date object for time 0. The getTime() method should also
** result in 0, but in Mac Netscape 2.x, the date is actually skewed by an
** hour. This function corrects for the skew by subtracting the skew
** amount from the Date object.
*/
function fixCookieDate(theDate)
{
var testDate = new Date(0);
var skew = testDate.getTime();
if (skew > 0)
theDate.setTime(theDate.getTime() - skew);
}
/* Cookie_get()
** ============
** Returns the stored value of the cookie or
** an empty string if the cookie does not exist.
*/
function Cookie_get()
{
// Get the document cookie.
var theWholeCookie = document.cookie;
// Look for the name of the cookie in the document's cookie.
var cookieStart = theWholeCookie.indexOf(this.name);
if (cookieStart == -1)
return ""; // The cookie wasn't found, so we return an empty string.
else
cookieStart += this.name.length + 1; /* Add the length of the
** cookie name to the starting
** value. The extra 1 is to
** accomodate the "=" character
** in the cookie syntax
** name=value. */
// Find the ";" that marks the end of our cookie.
var cookieEnd = theWholeCookie.indexOf(";", cookieStart);
if (cookieEnd == -1)
cookieEnd = theWholeCookie.length; /* In the event that a semicolon
** isn't found, we'll return the
** remaining length of our cookie. */
// Grab the actual cookie from the entire cookie string.
var theCookie = theWholeCookie.substring(cookieStart, cookieEnd);
// Return the decoded cookie.
return unescape(theCookie);
}
/* Cookie_store()
** ==============
** Constructs the cookie by assigning all of the various
** cookie components to document.cookie.
*/
function Cookie_store(string)
{
document.cookie =
this.name + "=" + escape(string) +
((this.expires) ? "; expires=" + this.expires.toGMTString() : "") +
((this.path) ? "; path=" + this.path : "") +
((this.domain) ? "; domain=" + this.domain : "") +
((this.isSecure) ? "; secure" : "");
}
/* Cookie_del()
** ============
** Deletes the current cookie by setting the expiration date to the beginning
** of time (as far as the computer is concerned) and providing an empty
** string for the cookie's value.
*/
function Cookie_del()
{
document.cookie =
this.name + "=" +
((this.expires) ? "; expires=" + (new Date(0)).toGMTString() : "") +
((this.path) ? "; path=" + this.path : "") +
((this.domain) ? "; domain=" + this.domain : "");
}
/* Creating cookie Methods
** =======================
** And, for our grand finale: Use the prototype property to make
** the above cookie functions (Cookie_store, Cookie_get, Cookie_del)
** into methods of a Cookie object, which are called as follows:
** myCookie.store(cookieData), myCookie.get(), myCookie.del()
*/
new Cookie(); // need to create a "dummy" Cookie object first
Cookie.prototype.store = Cookie_store;
Cookie.prototype.get = Cookie_get;
Cookie.prototype.del = Cookie_del;