.js Material

Results 1 to 2 of 2

Thread: .js Material

  1. #1
    Join Date
    Dec 1969

    Default .js Material

    I am showing the material below to help aid my question. I am curious why when I add the cookies.js to my jscript.asp file I get an Syntax error code 0. Yet it is straight out of the book.<BR>It would be ok to keep it in a cookies.js file but do I have to use an #include to call the library? I would have to edit 600 pages to do that so I do not want that. Lastly, can I call the cookies.js library from the jscript.asp file which I am already #including?<BR><BR>Is there a major difference between .js and .asp files?<BR><BR>1.9.2 Solution<BR>Use the cookies.js library shown in the Discussion as a utility for saving and retrieving cookies. To set a cookie via the library, invoke the setCookie( ) function, passing, at a minimum, the cookie&#039;s name and string value as arguments: <BR><BR>setCookie ("userID", document.entryForm.username.value);<BR>To retrieve a cookie&#039;s value, invoke the library&#039;s getCookie( ) function, as in: <BR><BR>var user = getCookie("userID");<BR>1.9.3 Discussion<BR>Example 1-1 shows the code for the entire cookies.js library. <BR><BR>Example 1-1. cookies.js library <BR>// utility function to retrieve an expiration date in proper<BR>// format; pass three integer parameters for the number of days, hours,<BR>// and minutes from now you want the cookie to expire (or negative<BR>// values for a past date); all three parameters are required,<BR>// so use zeros where appropriate<BR>function getExpDate(days, hours, minutes) {<BR> var expDate = new Date( );<BR> if (typeof days = = "number" && typeof hours = = "number" && <BR> typeof hours = = "number") {<BR> expDate.setDate(expDate.getDate( ) + parseInt(days));<BR> expDate.setHours(expDate.getHours( ) + parseInt(hours));<BR> expDate.setMinutes(expDate.getMinutes( ) + parseInt(minutes));<BR> return expDate.toGMTString( );<BR> }<BR>}<BR> <BR>// utility function called by getCookie( )<BR>function getCookieVal(offset) {<BR> var endstr = document.cookie.indexOf (";", offset);<BR> if (endstr = = -1) {<BR> endstr = document.cookie.length;<BR> }<BR> return unescape(document.cookie.substring(offset, endstr));<BR>}<BR> <BR>// primary function to retrieve cookie by name<BR>function getCookie(name) {<BR> var arg = name + "=";<BR> var alen = arg.length;<BR> var clen = document.cookie.length;<BR> var i = 0;<BR> while (i &#060; clen) {<BR> var j = i + alen;<BR> if (document.cookie.substring(i, j) = = arg) {<BR> return getCookieVal(j);<BR> }<BR> i = document.cookie.indexOf(" ", i) + 1;<BR> if (i = = 0) break; <BR> }<BR> return "";<BR>}<BR> <BR>// store cookie value with optional details as needed<BR>function setCookie(name, value, expires, path, domain, secure) {<BR> document.cookie = name + "=" + escape (value) +<BR> ((expires) ? "; expires=" + expires : "") +<BR> ((path) ? "; path=" + path : "") +<BR> ((domain) ? "; domain=" + domain : "") +<BR> ((secure) ? "; secure" : "");<BR>}<BR> <BR>// remove the cookie by setting ancient expiration date<BR>function deleteCookie(name,path,domain) {<BR> if (getCookie(name)) {<BR> document.cookie = name + "=" +<BR> ((path) ? "; path=" + path : "") +<BR> ((domain) ? "; domain=" + domain : "") +<BR> "; expires=Thu, 01-Jan-70 00:00:01 GMT";<BR> }<BR>}<BR>

  2. #2
    Join Date
    Dec 1969

    Default That code is all CLIENT JS...

    ...so you can&#039;t #include it or otherwise use it with SERVER-side JScript.<BR><BR>I don&#039;t know why you get a SYNTAX error, but you certainly will get runtime errors if you try to use any of that code in ASP: There&#039;s no such thing as a "document" object in server-side ASP.<BR><BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts