Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Oct 2011
    Thanked 0 Times in 0 Posts

    pull variable from cookie filename

    I'm working on an internal website at work and employees have a cookie created when they login to the customer support tool. The filename is cookie:username@domain.com/ and I'd like to use javascript to pull a variable for their username to plug into a URL for a unique link when they're viewing one of our intranet pages.

    I'm a Javascript newbie so any help is appreciated. @domain.com/ will always be the same but I don't know how to pull the unique username from the filename of the cookie. I don't need to actually read the cookie.


  • #2
    Senior Coder Logic Ali's Avatar
    Join Date
    Sep 2010
    Thanked 207 Times in 202 Posts
    str = "cookie:username@domain.com/" ;
    var uName = ( uName = str.match( /^cookie:([^@]+)@/ ) ) ? uName[ 1 ] : "" ;
    alert( uName );
    The above statements would extract the part of str betrween : and @. If I understand what you're doing, first you have to find a cookie name that matches the required format, and you must ensure that there is never more than one of those stored on any given browser or how would you distinguish them?

  • #3
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Thanked 4,749 Times in 4,711 Posts
    I give up. How can you even *READ* the cookie file names???

    In general, the browser will *NOT* give you access to files stored on the user's computer. You can do this with MSIE, using the Scripting.FileSystemObject ActiveX control, but only if the user's MSIE browser settings allow it (and even then it has to be approved each time it is used).

    Reading the cookie--without knowing or needing to know the filename--would be much the preferable way. It works cross-browser and requires no special permissions.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.


    Posting Permissions

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