JavaScript - Cookie Path Probem
Hi,
I have setting some cookies to track visitors to my site. I have my pages in folder music and in sub folders. I can access my site by typing: www.ms.webspace.com/sara/music So the domain will be: www.ms.webspace.com and the path: /sara/music/ but the broblem is that other cookies are attached to my cookieby going to www.ms.webspace.com or any link in it. Is the problem from setting the path? If not how can I filter my cookie so i can just display my cookies only, I use one function to display all the cookies. Thanks. Similar TutorialsUnfortunately, this isn't standard cookie stuff (I don't think). I have a compiled .exe loader for a program which includes an .html page which records the input of a textbox to a cookie. That much works OK. But reading it back isn't working. It seems the path is: ~~local~~/C:/Users/Terry/AppData/Local/Temp/td9/FrontPage%20Webs/1001(FINAL)(v1.2)/loader/ i.e. a temp dir related to the directory from where the .exe file was created. What I need is for the cookie to be available everywhe ~~local~~/ Is anyone able to shed some light? Adding ";path=/"; isn't working. I guess it's something to do with being compiled? Hi all First post. I don't normally use Javascript apart from a few browser workarounds, but I have a requirement to set a country cookie and it was working when all my pages were in the same directory, but now that I've added subdirectories, it sets a new cookie for each directory instead of one sitewide. Here's the code (which I edited from some found on the internet): Code: // JavaScript Document <!-- function ReadCookie() { var NameOfCookie="Country"; if(document.cookie.length > 0) { begin = document.cookie.indexOf(NameOfCookie+"="); if(begin != -1) { // our cookie was set. // The value stored in the cookie is returned from the function begin += NameOfCookie.length + 1; end = document.cookie.indexOf(";",begin); if(end == -1) end = document.cookie.length; country=(document.cookie.substring(begin,end)); if (country=="HongKong")document.location.href='hk/'; if (country=="Australia")document.location.href='au/' if (country=="NewZealand")document.location.href='nz/' } } } function SetCookie(cookieName,cookieValue) { var today = new Date(); var expire = new Date(); var nDays=365 expire.setTime(today.getTime() + 3600000*24*nDays); document.cookie = cookieName+"="+escape(cookieValue) + ";expires="+expire.toGMTString(); } //--> Then on the homepage links I use: Code: <a href="hk/" onClick="SetCookie('Country','HongKong');">Hong Kong</a> Then on the subdirectory pages, I have a reset button which allows you to return to the homepage and disable the redirect. Code: <a href="../" onClick="SetCookie('Country','Null');">HONG KONG</a> So I just need the path=/ to be added somewhere is that right? I tried changing the last line of the main code to: Code: + ";expires="+expire.toGMTString()+" path=/"; but that only worked in IE not Firefox. Can anyone help? Thank you! thingswelike Hi, I have a script that sets a number of cookies based on a set of results returned from an external website. The file sits in the cgi-bin folder (it has to, as this is where the data is processed and results returned) and when the data is returned it is stored in a number of cookies before redirecting to a results page in the website root to display the data. The problem, before I display any code, is that one of the cookies is setting its path to the /cgi-bin folder, meaning when the page redirects back to the website this particular cookie is not accessible. However, what is even more unusual is that this only happens in Safari. Here is the code: Code: <script> // function to set cookie function setCookie(c_name,value,expiredays) { var exdate=new Date(); exdate.setDate(exdate.getDate() + expiredays); document.cookie = c_name + "=" + value + ((expiredays==null) ? "" : ";expires=" + exdate.toGMTString()) + "; path=/"; } </script> <!-- the divs below are populated with data --> <div style="display:none;" id="listcount"><!--matchcode name="LISTCOUNT" --></div> <div style="display:none;" id="nearrecs"><!--matchcode name="NEARESTRECORDS" --></div> <div style="display:none;" id="distances"><!--matchcode name="MILES" --></div> <div style="display:none;" id="ambigrecs"><!--matchcode name="AMBIGLIST" --></div> <script type="text/javascript"> // data is extracted from the divs above var ncSnip = document.getElementById("nearrecs").innerHTML; var ncDistances = document.getElementById("distances").innerHTML; var listCount = document.getElementById("listcount").innerHTML; var ambig = document.getElementById("ambigrecs").innerHTML; if (ambig != "") { //document.getElementById("result").innerHTML = "ambig"; setCookie("ckAmbig", ambig, 365); setCookie("ckResults", ncSnip, -1); setCookie("ckDistances", ncDistances, -1); setCookie("ckListCount", listCount, 365); window.location="http://xxxxx"; } else if (ncSnip != "") { //document.getElementById("result").innerHTML = "records"; setCookie("ckDistances", ncDistances, 365); setCookie("ckResults", ncSnip, 365); setCookie("ckAmbig", ambig, -1); setCookie("ckListCount", listCount, 365); window.location="http://xxxxxx"; } else { //document.getElementById("result").innerHTML = "none"; setCookie("ckAmbig", ambig, -1); setCookie("ckResults", ncSnip, -1); setCookie("ckDistances", ncDistances, -1); setCookie("ckListCount", listCount, 365); window.location="http://xxxxxx"; } </script> The specific cookie that is being set to the wrong path is the 'ckResults' cookie. Can anyone help? Does the code above shed any light as to why this one cookie would set an incorrect path in Safari only? I've done LOTS of Googling on this subject. I can write cookies beautifully to '[other data]; path=/Stats' but I can't figure out how on EARTH to read from it. How do I access the data there? If I just say path=/ then it will read beautifully, but I need to be able to have different paths for what I want this to ultimately do.
Hi everyone, I am using the Colorbox javascript on my site. It looks fine on my PC in IE8, FF, and Chrome however one friend showed me a screenshot of it working on her PC, and it was all messed up (the screenshot, http://www.minifigtimes.com/images/notright.jpg) I've asked another friend to review it and it was fine on his FF and Chrome. Not sure how to fix it if I can't see it not working now Anyway I would really appreciate it if people could click on the script and tell me if it works ok for them or not (it is supposed to popup a little window with some text and a picture, Example here of what it should look like: http://www.minifigtimes.com/images/should.jpg ) The relevant page is http://www.minifigtimes.com and the script is activated by any of the links circled in the following pic: http://www.minifigtimes.com/images/links.jpg Any help really appreciated. Thanks. Hi everyone, I am using a jQuery cookie script to set the cookie of some elements on my website. One of the problems is that I need the cookie to not expire after one day, I need it to expire after a while (I'm going to start off with a year). Here's my script, the red part is what I've been editing. Code: /** * Cookie plugin * * Copyright (c) 2006 Klaus Hartl (stilbuero.de) * Dual licensed under the MIT and GPL licenses: * http://www.opensource.org/licenses/mit-license.php * http://www.gnu.org/licenses/gpl.html * */ /** * Create a cookie with the given name and value and other optional parameters. * * @example $.cookie('the_cookie', 'the_value'); * @desc Set the value of a cookie. * @example $.cookie('the_cookie', 'the_value', { expires: 7, path: '/', domain: 'jquery.com', secu true }); * @desc Create a cookie with all available options. * @example $.cookie('the_cookie', 'the_value'); * @desc Create a session cookie. * @example $.cookie('the_cookie', null); * @desc Delete a cookie by passing null as value. Keep in mind that you have to use the same path and domain * used when the cookie was set. * * @param String name The name of the cookie. * @param String value The value of the cookie. * @param Object options An object literal containing key/value pairs to provide optional cookie attributes. * @option Number|Date expires Either an integer specifying the expiration date from now on in days or a Date object. * If a negative value is specified (e.g. a date in the past), the cookie will be deleted. * If set to null or omitted, the cookie will be a session cookie and will not be retained * when the the browser exits. * @option String path The value of the path atribute of the cookie (default: path of page that created the cookie). * @option String domain The value of the domain attribute of the cookie (default: domain of page that created the cookie). * @option Boolean secure If true, the secure attribute of the cookie will be set and the cookie transmission will * require a secure protocol (like HTTPS). * @type undefined * * @name $.cookie * @cat Plugins/Cookie * @author Klaus Hartl/klaus.hartl@stilbuero.de */ /** * Get the value of a cookie with the given name. * * @example $.cookie('the_cookie'); * @desc Get the value of a cookie. * * @param String name The name of the cookie. * @return The value of the cookie. * @type String * * @name $.cookie * @cat Plugins/Cookie * @author Klaus Hartl/klaus.hartl@stilbuero.de */ jQuery.cookie = function(name, value, options) { if (typeof value != 'undefined') { // name and value given, set cookie options = options || {}; if (value === null) { value = ''; options.expires = -1; } var expires = ''; if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) { var date; if (typeof options.expires == 'number') { date = new Date(); date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000 * 365)); } else { date = options.expires; } expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE } // CAUTION: Needed to parenthesize options.path and options.domain // in the following expressions, otherwise they evaluate to undefined // in the packed version for some reason... var path = options.path ? '; path=' + (options.path) : ''; var domain = options.domain ? '; domain=' + (options.domain) : ''; var secure = options.secure ? '; secure' : ''; document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join(''); } else { // only name given, get cookie var cookieValue = null; if (document.cookie && document.cookie != '') { var cookies = document.cookie.split(';'); for (var i = 0; i < cookies.length; i++) { var cookie = jQuery.trim(cookies[i]); // Does this cookie string begin with the name we want? if (cookie.substring(0, name.length + 1) == (name + '=')) { cookieValue = decodeURIComponent(cookie.substring(name.length + 1)); break; } } } return cookieValue; } }; Hi all, I have been searching for a long time to obtain the UNC path of a file using the FileUpload control using javascript.. Is there any way to obtain it. Can anyone please guide me to the answer. Thank you, Aswin This page should work, but it doesn't. My debugging says that I have a invalid character on line 2 and on line 39 it is "object expected". Here's the page: <HTML> <HEAD> <TITLE>The Golf Page</TITLE> <STYLE> BODY {font-family:Arial, Helvetica, sans-serif; font-size: 18pt; color:blue; background-color:rgb(255,255,128)} </STYLE> <SCRIPT SRC="Ball.gif"> var x = new Array(-395, -389, -383, -377, -371, -365, -359, -353, -346, -340, -334, -328, -322, -316, -310, -304, -297, -291, -285, -279, -273, -267, -261, -255, -248, -242, -236, -230, -224, -218, -212, -206, -199, -193, -187, -181, -175, -169, -163, -157, -150, -144, -138, -132, -126, -120, -114, -108, -101, -95, -93, -91, -88, -86, -83, -81, -78, -76, -73, -71, -69, -66, -64, -61, -59, -56, -54, -51, -49, -47, -44, -42, -39, -37, -34, -32, -29, -27, -24, -22, -20, -17, -15, -12, -10, -7, -5, -2, 0); var y = new Array(-300, -300, -300, -299, -298, -297, -296, -294, -292, -290, -288, -285, -282, -279, -276, -272, -268, -264, -260, -255, -250, -245, -240, -234, -228, -222, -216, -209, -202, -195, -188, -180, -172, -164, -156, -147, -138, -129, -120, -110, -100, -90, -80, -69, -58, -47, -36, -24, -12, 0, -5, -10, -14, -18, -22, -25, -29, -32, -34, -37, -39, -41, -43, -45, -46, -47, -48, -48, -48, -48, -48, -48, -47, -46, -45, -43, -42, -40, -37, -35, -32, -29, -26, -23, -19, -15, -11, -6, 0); index=0 function moveBall() { if(index <=[x.length-1]) { placeIt("Ball", x[index], y[index]); index++; setTimeout("moveBall()", 5); } else { ("showIt()", 5); setTimeout("showIt('Slogan')", 5); setTimeout("showIt('Slogan1')", 10); setTimeout("showIT('Marquee')", 15); } } </SCRIPT> </HEAD> <BODY onLoad="moveBall(Ball);"> <DIV ID="Marquee" visibility:hidden font-family: Time New Roman, Times, serif; font-style:italic> <CENTER> <MARQUEE BGCOLOR="#BBBBBB"> A beautiful day for GOLF...Sunny...No WINDS...TEMP:68-70 </MARQUEE> </CENTER> </DIV> <SCRIPT SRC="Golf.js"></SCRIPT> <DIV ID="Title" STYLE="border-left:1px solid blue; border-right:3px solid blue; border-top:1px solid blue; border-bottom:3px solid blue; padding-left:395;padding-top:260;padding-bottom:0; background-color:rgb(0,255,0)"> THE G<SPAN ID="Ball" position:relative; left:0; top:0><IMG SRC="Ball.gif" BORDER=0 width="17" height="17"></SPAN>LF PAGE </DIV> <DIV ID="Slogan" STYLE="color:black; font-family: Times New Roman, Times, serif; font-style:italic; font-weight:bold; position:absolute; left:120; top:100; z-index:2; visibility:hidden"> Your Online Source of Golf Equipment </DIV> <DIV ID="Slogan2" STYLE="color:white; font-family: Times New Roman, Times, serif; font-style:italic; font-weight:bold; position:absolute; left:121; top:101; z-index:1; visibility:hidden"> Your Online Source of Golf Equipment </DIV> </BODY> </HTML> The function moveBall and its contents should be checked as well, although it should be correct. But the page won't load properly. The marquee is suposed to be hidden until the function executes, and it is displayed. As far as I know the only errors are in the onLoad and function, everything else is right. Any help would be appreciated. Thanks Fairly new the javascript, as in only been tinkering around for about a day. So forgive me if this is a simple question. At the moment I have the following function for handling events such as onclick, mouseover, mouseout. Code: function switcher(action, img){ switch(action){ case "hover": //mouse is on image document.imgSeat.src = "images/hover.gif"; break; case "click": //mouse has clicked image document.imgSeat.src = "images/click.gif"; break; default: //mouse elsewhere document.imgSeat.src = "images/defaulter.gif"; break; } } And the html the function refers to Code: <body> <div id="imagesholder"> <a href="#nerf"><img border="0" id="seat0" src="images/available.gif"></a> </div> </body> What im trying to do change my function so that instead of it being hard coded for the id "imgSeat" i can use the id passed through the parameter "img" instead. However I seem to be banging my head against the wall. I've tried using the following Code: document.getElementById(img).src = "images/available.gif"; //no error, just does nothing //where img is "0" instead of "seat0" document.seat[img].src = "images/available.gif"; //error: document.seat is undefined Would be extremely greatful if someone should push me in the right direction or show me what im doing wrong. Is this possible? Let me clarify: I need a way for a html page or something similar be able to determine what it's full path is. It must self-determine this. Can javascript help me with this? Any recommendations of what route I should take to figure this out? Thanks! I'm working on a site built through Squarespace, and I've run into some limitations. They've told me it's possible to build a Javascript to pull specific images from one page's journal entries and place them (with links to the entry) on other pages. Can somebody send me in the right direction on how I would do this? Basically I want to find a most recent posting tagged with a specific category, find the file file path of it's related image, and make that appear on the page that my javascript is on. is there some way to searching through multiple path or recursively searching through a path (folders and subfolders) using the code below which seems to search only one node in the tree? Many Thanks. there are basically subfolders in \documents and then subfolders therein. i would like to search it therein for all kinds of files/filenames based on "search criteria". one more thing - is it ok/advisable to use active x objects considering most modern browsers have it disabled or give warnings? Code: <script> var Fo =new ActiveXObject("Scripting.FileSystemObject"); var StrOut = new String(); var FileName = new String(); var Extention = new String(); function FindFile(FOo) { var FSo = new Enumerator(FOo.Files); for(i=0;!FSo.atEnd();FSo.moveNext()) { if(FileName == "*" || FSo.item().name.slice(0,FSo.item().name.lastIndexOf(".")).toLowerCase().indexOf(FileName)>-1) if(Extention == "*" || FSo.item().name.slice(FSo.item().name.lastIndexOf(".")+1).toLowerCase().indexOf(Extention)>-1){ StrOut += "<tr "+ ((i%2)? "":"bgcolor=#C4E3F2") +"><td width=50%><font class=find>" + FSo.item().name + "</font></td><td width=25%><font class=find>" + FSo.item().type + "</font></td><td width=50%><font class=find>"+ String(FSo.item().size/(1024*1024)).slice(0,3) +" MB</font></td></tr>"; i++ } } } function Search() { FileName = (search.value.lastIndexOf(".")>-1)? search.value.slice(0,search.value.lastIndexOf(".")):(search.value.length>0)? search.value.toLowerCase():"*"; //Get Searched File Name Extention = (search.value.lastIndexOf(".")>-1)? search.value.slice(search.value.lastIndexOf(".")+1).toLowerCase():"*"; // Get Searched File Extention Name if(path.value.length>0 && Fo.FolderExists(path.value)){ StrOut = "<table border=0 width=100% cellspacing=0>" FindFile(Fo.GetFolder(path.value)); outPut.innerHTML = StrOut+"</table>"; } else alert("Insert Correct Path Address"); } </script> Code: <BODY topmargin="0" leftmargin="0"> <table border=0 width=100% cellspacing="0" style="border-collapse: collapse" cellpadding="2"><tr> <td dir="ltr" bgcolor="#FFD9D9"><b><font face="Verdana" size="2">Filename : </font></b> </td> <td dir="ltr" bgcolor="#C4E3F2"> <input size=50 type=text id=search name=search class="Find"></td> </tr><tr> <td dir="ltr" bgcolor="#C4E3F2"> <p dir="ltr"></td> <td bgcolor="#FFD9D9"><input size=50 type=hidden value="\Documents" id=path name=path class="Find" > <input type=button value="Search" onClick=Search() class="Find"></td> </tr><tr> <td colspan=2 align=left bgcolor="#FFFFFF"><font face=Verdana size=2><b>Search Result</b></font><hr></td> </tr><tr> <td colspan=2 bgcolor="#FFFFFF"><div id=outPut></div></td> </tr></table> </BODY> </HTML> Hi all, I have an .xsl file that reads an xml file and populates an html file and that is working well. I want to have many xml files (one per project) and one .xsl and html file. The goal would be to get the user to browse for the particular xml file they want to use and have the html file reference the path and file name. There will be a main page where the user will browse for the xml file in question. When they hit submit, the information (document path) is passed to the html file and the html file opens with information from the xml page they selected .In my html file I have the following: Code: xml.load(''12345.xml'') Basically I would like to somehow browse to the xml file in question and pass that variable (file path and name) to the html file and replace "1234.xml" with the path and name selected by the browse section. Does this make sense? Thanks. Reply With Quote 01-22-2015, 11:04 PM #2 Old Pedant View Profile View Forum Posts Supreme Master coder! Join Date Feb 2009 Posts 28,310 Thanks 82 Thanked 4,754 Times in 4,716 Posts The easiest way to do this would be via server-side code. For example, just have a PHP page the includes the desired ".xml" file into a page that is already setup with the XSLT. I vaguely recall reading that there is a way to "apply" XSLT to a dynamic set of XML, but the function named apply() in XSLT doesn't do anything like this. Still, the easiest way to control this would be via the server side code. Heck, that would even allow you to string together "pieces" of XML from various files to create the final document. Hi everyone! Got a quick (cookie) question. I looked on the internet for some cookie scripts (redirect ones), but unfortunately haven't been too lucky with these. What I want to do is the following: When the cookie is not found it goes to my main page, for example: "www.anynamehere.com" On the main page I can select where I want to go - 'Contacts', 'News', 'Forums' and so on. The main page has a drop down list with these options, each option has it's own link. When I click on 'continue' and go to the specific link (ex. www.anynamehere.com/contacts.html) it should remember my selection, so next time I log into www.anynamehere.com it's automatically will take me to contacts.html. I will not see the main page anymore. Now, if from the contacts page I select 'News' and go to www.anynamehere.com/news.html it has to remember that link as well. So if I close my browser and then reopen it, it should take me to www.anyname.com/news.html. I hope that makes sense. If anyone can give me any pointers I would greatly appreciate it. Maybe there is a script like that available online, I just wasn't lucky enough to find one. Thank you in advance! Hello. I am a neewb, so bare with me. This code is not working correctly for some reason. If I use it in Internet Explorer it will work, but only if you bring up the history in the url tab. You cannot refresh it for whatever reason. so basically it works in Explorer but no refresh. The big problem is Mozilla. I will not work at all. I have all of the cookies set for third party, remember last visit and so on. It will only display the welcome page for first time visitor. Then it will show the subsequent page, however it will not increment the count +1. I am not sure what is going on here, Explorer works, but with no refresh, and Mozilla does not really work at all? Here is my script currently: <script type="text/javascript"> /* <![CDATA[ */ function hitMySite() { var lastDate = new Date(); lastDate.setMonth(lastDate.getMonth()); var dateString = (lastDate.getMonth() + 1) + "/" + lastDate.getDate() + "/" + lastDate.getFullYear(); if (document.cookie != "") { counter = document.cookie.split("=")[1]; counter = parseInt(counter) + 1; date = document.cookie.split(":")[2]; var expireDate = new Date(); expireDate.setMonth(expireDate.getMonth() + 12); document.cookie = "counter=" + counter + ":date:" + dateString + ";expires=" + expireDate.toGMTString(); document.write("<h1>You last visited this page on: " + date + "<br />You have been to this page " + counter + " times.</h1>"); } else { document.write("<h1>Welcome to my Web site! This is your first visit here so be sure to bookmark my page!</h1>"); var counter = 1; var expireDate = new Date(); expireDate.setMonth(expireDate.getMonth() + 12); document.cookie = "counter=" + counter + ":date:" + dateString + ";expires=" + expireDate.toGMTString(); } } /* ]]> */ </script> </head> <body onload="hitMySite()"> </body> </html> Hi im kind of new to cookies in Javascript. But after reading a few tutorials on how the work I started to wonder. Is it possible to grab a cookie made by my phpbb forum? I would love to be able to login on my site using my phpbb forum cookies. Anway if this is a bad idea ore won't work for any reason plz let me know. Thanks |