JavaScript - Remember Me Cookie Issue
hi my login form is inside a popup at www.nandahosting.co.uk at the top right have corner if you click "Customer Login"
the login form has an remember me. after i have logged in if i go back to the homepage, when i click customer login it asks me for my username and password again, its something to do with the form being inside the popup i think. this is the form Code: <div id="popUpDiv" style="display:none;"> <div id="tbright"> <a href="#" onclick="popup('popUpDiv')"><img src="<%= url_prefix %>./theme-images/xclose.png" alt="close" style="float: right; width: 30px; height:26px;" class="close"/></a> <h4>Customer Login</h4> <form action='login' method='post'> <div id="boxleft"> <p><label for="username2">Username:</label><input name='username' type='text' value='' id='username2'/></p> <p><label for="password">Password:</label><input type='password' name='password' value='' id='password'/></p> <p><label for="permanent">Remember me?</label><input type='checkbox' name='permanent' style="margin: 0 0 20px 10px; width: 13px; float: right; height: 13px;" value='1' id='permanent'/></p> </div> <div id="boxright"> <input name="" type="submit" class="btn" value="Login" style="position: relative;"/> <p class="link"><b>New Customer? - </b><a href="<%= url_prefix %>register">Create an account</a></p> <p class="link"><a href="<%= url_prefix %>password-reminder">Forgotten your Password?</a></p> </div> </form> </div> </div> This is the javascript for the popup Code: function toggle(div_id) { var el = document.getElementById(div_id); if ( el.style.display == 'none' ) { el.style.display = 'block';} else {el.style.display = 'none';} } function blanket_size(popUpDivVar) { if (typeof window.innerWidth != 'undefined') { viewportheight = window.innerHeight; } else { viewportheight = document.documentElement.clientHeight; } if ((viewportheight > document.body.parentNode.scrollHeight) && (viewportheight > document.body.parentNode.clientHeight)) { blanket_height = viewportheight; } else { if (document.body.parentNode.clientHeight > document.body.parentNode.scrollHeight) { blanket_height = document.body.parentNode.clientHeight; } else { blanket_height = document.body.parentNode.scrollHeight; } } var blanket = document.getElementById('blanket'); blanket.style.height = blanket_height + 'px'; var popUpDiv = document.getElementById(popUpDivVar); popUpDiv_height=blanket_height/2-150;//150 is half popup's height popUpDiv.style.top = popUpDiv_height + 'px'; } function window_pos(popUpDivVar) { if (typeof window.innerWidth != 'undefined') { viewportwidth = window.innerHeight; } else { viewportwidth = document.documentElement.clientHeight; } if ((viewportwidth > document.body.parentNode.scrollWidth) && (viewportwidth > document.body.parentNode.clientWidth)) { window_width = viewportwidth; } else { if (document.body.parentNode.clientWidth > document.body.parentNode.scrollWidth) { window_width = document.body.parentNode.clientWidth; } else { window_width = document.body.parentNode.scrollWidth; } } var popUpDiv = document.getElementById(popUpDivVar); window_width=window_width/2-150;//150 is half popup's width popUpDiv.style.left = window_width + 'px'; } function popup(windowname) { blanket_size(windowname); window_pos(windowname); toggle('blanket'); toggle(windowname); } i am no good at javascript but could someone please help me, so that if customers has clicked the remember me box, if they go to the homepage then when they click customer login it will redirect them straight away if they have previously ticked the remember me box. thankyou so much. Similar TutorialsPlease assist, I have the following code to remember form inormation but it does not seem to work. Probably something stupid. Code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Contact Page</title> <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" /> <link rel="stylesheet" href="yorkie.css" type="text/css" /> <script type="text/javascript"> /* <![CDATA[ */ // Confirm resetting of forms. function confirmReset() { var resetForm = confirm("Are you sure you want to reset the form?"); if (resetForm == true) return true; return false; } // If box clicked value within disappears function Focus(element) { if (element.value == element.defaultValue) { element.value = ''; } } // If nothing typed and box onblur the default value is restored within function Blank(element) { if (element.value == '') { element.value = element.defaultValue; } } // Submission of Contact Form Verified function verifySubmission() { var retValue = true; if (document.forms[2].email.value == "Enter Email Address" || document.forms[2].firstname.value == "Enter First Name" || document.forms[2].lastname.value == "Enter Last Name" || document.forms[2].telephone.value == "Enter Contact number") { window.alert("You did not fill in one of the following required fields: First Name, Last Name, Email Address, or Telephone Number."); retValue = false; } return retValue; } // Email address verified as a valid email address function validateEmail(formObject) { var email = formObject.value; var emailCheck = /^[_\w\-]+(\.[_\w\-]+)*@[\w\-]+(\.[\w\-]+)*(\.[\D]{2,3})$/; if (emailCheck.test(email) == false) { window.alert("The e-mail address you entered does not appear to be valid."); formObject.value = formObject.defaultValue; return false; } formObject.value = email.toLowerCase(); return true; } // Telephone number verified as a valid 10 digit number with no alpha characters function verifyPhone(number) { var phone = number.value; var phoneCheck = /^(\d{10})$/; if(phoneCheck.test(phone) == false) { window.alert("The telephone number you entered does not appear to be valid."); number.value = number.defaultValue; return false; } return true; } // Show additional contact form details onclick of yes radio button function showDiv() { document.getElementById('breeders').style.visibility = 'visible'; } // Hide certain contact form info onclick of No radio button function hideDiv() { document.getElementById('breeders').style.visibility = 'hidden'; } // SAVE FORM INFORMATION FOR THE NEXT VISIT function saveSelections(frm) { var setvalue; var fieldType; var index; var formname = frm.name; // CookieExpiry in 30 days. var today = new Date(); var exp = new Date(today.getTime()+30*24*60*60*1000); var string = "formname=" + formname + "|"; var cookieName = formname; var n = frm.length; for (i = 0; i < n; i++) { e = frm[i].name; fieldValue = frm[i].value; fieldType = frm[i].type; // Radio Buttons if (fieldType == "radio") { for (x=0; x < frm.elements[e].length; x++) { if (frm.elements[e][x].checked) { index = x } } string = string + index + "\|"; } // Text, Textarea, and dropdowns if ((fieldType == "text") || (fieldType == "textarea") || (fieldType == "select")) { string = string + frm.elements[e].value + "\|"; } // Checkboxes if (fieldType == "checkbox") { if (frm.elements[e].checked==true) { var setvalue = "1"; } if (frm.elements[e].checked==false) { var setvalue = "0"; } string = string + setvalue + "\|"; } // Hidden field if (fieldType == "hidden") { string = string + frm.elements[e].value + "\|"; } } setCookie(cookieName, string, exp); } // Load Form Fields from saved cookie function loadSelections(frm) { var e; var z; var x; var cookieName; var fieldArray; var fieldValues; var fieldValue; var formname = frm.id; // Retrieve form elements from cookie and split into array. cookieName = formname; fieldValues = getCookie(cookieName); fieldArray = fieldValues.split("\|"); var n = frm.length; for (i = 0; i < n; i++) { e = frm[i].name; z = i; z++; var fieldType = frm[i].type; var fieldValue = fieldArray[z]; // Radio Buttons if (fieldType == "radio") { x = fieldValue; frm.elements[e][x].checked = true; } // Text, Textarea, and dropdowns if ((fieldType == "text") || (fieldType == "textarea") || (fieldType == "select")) { frm.elements[e].value = fieldValue; } // Checkboxes if (fieldType == "checkbox") { var fld_checkbox = fieldValue; if (fld_checkbox == "1") { frm.elements[e].checked = true; } } // Hidden fields if (fieldType == "hidden") { frm.elements[e].value = fieldValue; } } } // COOKIE FUNCTIONS function setCookie(name, value, expires) { document.cookie= name + "=" + escape(value) + ((expires) ? "; expires=" + expires.toGMTString() : ""); } function getCookie(name) { var dc = document.cookie; var prefix = name + "="; var begin = dc.indexOf("; " + prefix); if (begin == -1) { begin = dc.indexOf(prefix); if (begin != 0) return null; } else { begin += 2; } var end = document.cookie.indexOf(";", begin); if (end == -1) { end = dc.length; } return unescape(dc.substring(begin + prefix.length, end)); } /* ]]> */ </script> </head> <body class="contact" onload="var begin=setInterval('changeBanner()',9000); currentClock(); currentDate(); document.getElementById('breeders').style.visibility = 'hidden'; " onunload="saveSelections(document.forms[0])"> <table width="92%"> <form action="mailto:lynette@sayorkies.co.za, subject=Contact Form" method="post" enctype="text/plain" onsubmit="return verifySubmission()" onreset="return confirmReset();"> <table class="center" cellpadding="5" border="1"> <!-- This enters a horizontal line --> <tr><td><hr /></td></tr> <!-- This is for the personal information --> <tr><td><strong>Tell us who you a </strong></td></tr> <tr><td><input type="text" name="firstname" size="25" maxlength="35" value="Enter First Name" onfocus="Focus(this);" onblur="Blank(this);" /> * <input type="text" name="lastname" style="margin-left: 52px;" size="25" maxlength="35" value="Enter Last Name" onfocus="Focus(this);" onblur="Blank(this);" /> *</td></tr> <!-- This is for the contact information --> <tr><td><strong>Your Contact details:</strong></td></tr> <tr><td><input type="text" name="email" size="30" maxlength="60" value="Enter Email Address" onfocus="Focus(this);" onblur="Blank(this); validateEmail(this)" /> * <input type="text" name="telephone" style="margin-left: 20px;" size="20" maxlength="10" value="Enter Contact number" onfocus="Focus(this);" onblur="Blank(this); verifyPhone(this)" /> * </td></tr> <!-- This is where you enter your message also select what type of message--> <tr><td><strong>Your Message:</strong></td></tr> <tr><td align="left">What is your message about?<br /> <input type="radio" name="type" value="compliment" /> Compliment <input type="radio" name="type" value="complaint" /> Complaint <input type="radio" name="type" value="general" checked="checked" /> General <input type="radio" name="type" value="enquiry" /> Enquiry <input type="radio" name="type" value="feedback" /> Feedback</td></tr> <tr><td align="center"><textarea name="message" rows="6" cols="45" onfocus="Focus(this);" onblur="Blank(this)">Enter your message here...</textarea></td></tr> <!-- Additional information --> <tr><td align="left">Are you looking to purchase a Yorkie puppy?<br /> <input type="radio" name="purchase" value="yes" /> Yes <input type="radio" name="purchase" value="no" checked="checked" /> No</td></tr> <tr><td align="left">Do you own a Yorkie?<br /> <input type="radio" name="owner" value="yes" onclick="showDiv()" /> Yes <input type="radio" name="owner" value="no" checked="checked" onclick="hideDiv()" /> No<br /> <!-- If answer is no above the below questions are hidden, if yes then they appear --> <div id="breeders"> How many? <select name="qnty" size="1"> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> <option value="5">5+</option></select> Are you a breeder? <input type="radio" name="breeder" value="yes" /> Yes <input type="radio" name="breeder" value="no" checked="checked" /> No</div></td></tr> <!-- Subscriptions --> <tr><td align="left">Do you wish to subscribe to the following?<br /> <input type="checkbox" name="subscribe" value="letter" checked="checked" /> Monthly Newsletter<br /> <input type="checkbox" name="subscribe" value="pups" /> Notification of a new litter<br /> <input type="checkbox" name="subscribe" value="updates" /> Notification of site updates<br /> <input type="checkbox" name="subscribe" value="register" /> Registrations</td></tr> <!-- Add a picture file --> <tr><td align="left">Upload your favourite Yorkie photo for the Picture of the Month.<br /> <input type="file" name="upload" accept="image/gif, image/jpeg" size="30" style="margin-left: 15px; margin-top:5px;" /></td></tr> <!-- This enters a horizontal line --> <tr><td><hr /></td></tr> <tr><td align="center">Required fields marked with *</td></tr> <!-- Buttons to clear the form or to submit the form --> <tr><td align="center"><input type="reset" value="Clear the Form" /> <input type="submit" value="Send your message" /></td></tr> </table></form<script type="text/javascript">loadSelections(document.forms[0]);</script> </body> </html> Console Error: Unable to get value of the property 'split': object is null or undefined for this line: Code: fieldArray = fieldValues.split("\|"); I am hitting a brick wall, dont know what to do? Hi, I have a website where the user can navigate different categories by tab. The problem is, when they're on a tab other than the default one and they refresh the page or click to another page, it puts them back on the first tab. I know this can be solved by using a session cookie of some type, I just need some help on implementing it into my site. http://www.thatswhyimbroke.com/ - so you can see what i'm talking about. If you look at the different tabs: Price High, price low, food & drink, etc. I want the user to be able to go to one of those, click to page 2 or refresh, and still be on that tab. Any help would be much appreciated! I have been trying for some time now to find a script to create a cookie for the following, so that the user selected font size is remebered throughtout the site. I have traweled the internet for some time now but all to no avail, the only guides i can find are for resizing a single element, which is no good for what i require. The code i already have is: <script type="text/javascript"> //Specify affected tags. Add or remove from list: var tgs = new Array( 'p', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'a', 'b', 'li', 'form.button' ); //Specify spectrum of different font sizes: var szs = new Array( 'x-small','small','medium','large','x-large' ); var startSz = 2; function ts( trgt,inc ) { if (!document.getElementById) return var d = document,cEl = null,sz = startSz,i,j,cTags; sz += inc; if ( sz < 0 ) sz = 0; if ( sz > 5 ) sz = 5; startSz = sz; if (!( cEl = d.getElementById( trgt ) ) ) cEl = d.getElementsByTagName( trgt )[ 0 ]; cEl.style.fontSize = szs[ sz ]; for ( i = 0 ; i < tgs.length ; i++ ) { cTags = cEl.getElementsByTagName( tgs[ i ] ); for ( j = 0 ; j < cTags.length ; j++ ) cTags[ j ].style.fontSize = szs[ sz ]; } } </script> On a seperate issue i would also like to know if there is a script i can put in to enable users to quickly return to the default font size (although it would not be the end of the world if such a thing is not possible). Hi Everyone, I've written a custom discussion forum in Perl for my site. There are five forums and each forum can have 100 active threads to read. I have a feature to remember (via writing a cookie) if a user has been in a thread and what was the last post at that time. Next time they click on the thread JavaScript reads the cookie and takes them right down to the first new post in a thread. Very similar to the green arrow on this forum. Each forum has its own cookie, to remember the last thread and post read during a visit: Code: Name=FORUM_A Value=2133.4|2133.4|2618.3|2607.11|2606.0|... Name=FORUM_B Value=2609.2|2597.2|2592.0|2589.1|2588.0|... Name=FORUM_C Value=2568.1|2569.3|2563.13|2605.4|2555.1|... Name=FORUM_D Value=2621.2|2620.4|2595.6|2585.0|2308.0|... Name=FORUM_E Value=2615.0|2612.3|2602.12|2608.2|2600.1|... This works just fine in Firefox and IE8. The problem I'm having in browsers like Safari is once the entire set of cookies get so long (100 entries in each of the five forums) Safari truncates the entire set of cookies during the: var cookieValue = document.cookie;. In the end the cookieValue variable is left with maybe 3 1/2 cookies, truncating off the last two. Is there any workaround for this or am I asking too much for javascript. It does work perfectly in Firefox, FF does not seem to have this truncating issue. Thanks in advance for everyone's assistance. 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; } }; I need help on some code
Code: function makefarm(){ document.getElementById("farms").value ++ ; document.getElementById("pop").value -=2 ; document.getElementById("coin").value -=10 ; document.getElementById("lumber").value -=20 ; document.getElementById("CIfarm").value ++ ; document.getElementById("CIfarm").value ++ ; document.getElementById("CIfarm").value ++ ; document.getElementById("CIfarm").value ++ ; document.getElementById("CIfarm").value ++ ; } function upgradefarm(){ document.getElementById("iron").value -=5 ; document.getElementById("coin").value -=20 ; document.getElementById("farmupgrades").value ++ ; } var food = function () { var f1 = document.getElementById('buttonhere'); var f2 = '<input type="button" value="Make Farm" onclick="makefarm()" /> Farms:<input type="text" id="farms" size="1" value=0 style="background-color:transparent;border:0px solid white;" READONLY/> <input type="button" value="Upgrade Farm" onclick="upgradefarm()" /> Farm Upgrades:<input type="text" id="farmupgrades" size="1" value=0 style="background-color:transparent;border:0px solid white;" READONLY/> <br/><br/><br/> Current Income:<input type="text" id="CIfarm" size="1" value=0 style="background-color:transparent;border:0px solid white;" READONLY/>'; f1.innerHTML = f2; } Code: Coin:<input type="text" id="coin" value=50 size="1" style="background-color:transparent;border:0px solid white;" READONLY /> Lumber:<input type="text" id="lumber" value=100 size="1" style="background-color:transparent;border:0px solid white;" READONLY /> Iron:<input type="text" id="iron" value=25 size="1" style="background-color:transparent;border:0px solid white;" READONLY /> Food:<input type="text" id="food" value=100 size="1" style="background-color:transparent;border:0px solid white;" READONLY /> POP:<input type="text" id="pop" value=10 size="1" style="background-color:transparent;border:0px solid white;" READONLY /> so if i press the makefarm() button it will add to the numbers but if i press it again they will got to zero how could i make it remember the numbers?(the input boxes are the second code) Dear all, Below the html and java code. After viewing using Internet Explorer, I did a selection from the autodropdown. Then I click on Click here to go to other page . You will see a quite different webpage. Then I click on the back button, in the left upper corner of IE window, so I see the previous webpage but.... the autodropdown does not remember my selection . How can we solve this? <html> <Head> <Script Language=JavaScript> Level1 = new Array("Ceramics","Chemicals") Ceramics = new Array("ELECTRONICS","ENVIRONMENTAL") Chemicals = new Array("METALLIC_SOAPS","OLEOCHEMICAL_DERIVATIVES") ELECTRONICS = new Array("Solder mask") ENVIRONMENTAL = new Array("Catalysts") METALLIC_SOAPS = new Array("Soap","Translucent soaps","Liquid soa[") OLEOCHEMICAL_DERIVATIVES = new Array("FA-pos","FA polfaideriv") function fillSelect(isValue,isNext){ isNext.style.display = ""; isNext.length = 1; curr = eval(isValue); for (each in curr) { isData = new Option(curr[each],curr[each]); isNext.add(isData,isNext.options.length); } } function getValue(isValue){ } </Script> </Head> <body> <center> <h4>Dependent Select List, within a form</h4> <Form name='Categories'> <p>Segment <Select name='List1' onChange="fillSelect(this.value,Categories.List2)"> <option selected>Make a selection</option> </Select> </p> <Select name='List2' onChange="fillSelect(this.value,Categories.List3)"> <option selected>Make a selection</option> </Select> <p></p> <Select name='List3' onChange="getValue(this.value)"> <option selected >Make a selection</option> </Select> </Form> </center> <Script> fillSelect('Level1',Categories.List1) Categories.List2.style.display = "none"; Categories.List3.style.display = "none"; </Script> <p>Click <a href="http://www.hetnet.nl">here</a> to go to other page</p> </body> </html> Hello all, I would like to implement a cookie feature on my site that when a user logs in a cookie is stored for him and the next time he comes back, he doesn't have to sign in. I have researched hotscripts and javascripts but the ones I have found have to do with the "remember me" and thats not quite what I want. I tried to manipulate it but with no luck. Any help with either posting code or an article would be greatly appreciated! Thanks a bunch-Dan My website is: ERBoH.com I have no experience with JS, just general knowledge of html/css. I had someone else write the site for me. They didn't know how to do this and pretty much just stopped talking to me... On my site, I have a video carousel (4 video thumbnails in a row, you press the > arrow, and it shows the next 4 video thumbnails, you click 1 video thumbnail, and it shows you the video above the carousel). The problem is, when you click on one of the thumbnails, it reloads the page, and the video carousel goes back to the beginning. So if you clicked the > arrow 3 times (ur on the 3rd set of thumbnails), then it brings you back to the 1st set. This is pretty annoying, especially if your planning on watching each video. My question is, is it possible to make some type of cookie or something to remember which set of thumbnails you were on in the carousel? So that, if your on the 3rd set, and click a video, instead of resetting to the 1st set, it keeps you on the 3rd set. If it is possible... how hard would it be to do? Is it something where I could just copy/paste a string of code, or would this be a huge project? Thanks for the advice. Hi, first off I am very green when it comes to this stuff, so it needs to be spelled out for me. First, I was using colorbox on one page for an image gallery, and that works fine. On a different page, I have jcarousellite, which works fine as well. If only I could mix them both on the same page. I couldn't figure that out, so what I did was create a new page each time I clicked a jcarousel image. It opens up a completely different page, but I styled it in such a way that it at least "mimics" how it might look if I were using a lightbox script. So my solution works fine for now EXCEPT that once I close the new page (that mimics lightbox) the jcarousellite slides revert back to starting position. I need the slides to stay at the last clicked position, and not go back to the beginning each time I refresh the page. I searched online and saw some people talk about an "afterEnd" callback, but this is where my ability stops. If anyone could help me here it would be fantastic. Here is my code: Code: $(document).ready(function() { $(".slider").jCarouselLite({ speed: 100, visible: 4, btnPrev: ".previous", btnNext: ".next", circular: true }); }); Hello everybody.. I have a problem with my code. I implement different Tabs into a Microsoft Office SharePoint Server 2007 site (.aspx). Now everytime I select a tab and refresh the whole page, IE7 cannot remmember the last session and navigate automatically back to tab1.. Properly I need to set Cookies. Im a beginner in using cookies and coding javascript.. I hope you can help me thanks [CODE] <%@ Page Language="C#" MasterPageFile="~masterurl/default.master" inherits="Microsoft.SharePoint.WebPartPages.WebPartPage, Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" metarogid="SharePoint.WebPartPage.Document" %> <%@ Register tagprefix="WebPartPages" namespace="Microsoft.SharePoint.WebPartPages" assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %> <%@ Register tagprefix="WebControls" namespace="Microsoft.SharePoint.Publishing.WebControls" assembly="Microsoft.SharePoint.Publishing, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %> <asp:Content runat="server" ContentPlaceHolderID="PlaceHolderAdditionalPageHead"> <!-- Tab Page Version 2.0 --> <!-- Questions and comments: peter@theallensite.com --> <!-- Blog: www.bitsofsharepoint.com --> <script type="text/javascript"> if(typeof jQuery=="undefined"){ var jQPath="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/"; document.write("<script src='",jQPath,"jquery.min.js' type='text/javascript'><\/script>"); } </script> <style> #tabs ul.tabNavigation{ margin: 0; padding: 0; list-style: none; height: 20px; /* Push the tabs 1px down to hide the top-border of the tabbedWindow */ position: relative; top: 1px; border-bottom: #998b7d 1px solid; } #tabs ul.tabNavigation li{ float: left; padding: 0; margin: 0 5px 0 0; background: none; } #tabs ul.tabNavigation a{ background-color: #fff; border: 1px solid #bbb; display: block; padding: 4px 0 1px; text-decoration:none } #tabs ul.tabNavigation a.selected{ font-weight: bolder; background-color: #fae8d9; border-bottom: #bbb 1px solid; } #tabs ul.tabNavigation a span{ padding: 0 10px; } #tabs div.tabbedWindow{ background-color: #fff; } #tabs ul.tabNavigation a:hover{ background-color: #F0F0F0 ; } .style1 { border: 0 solid #c0c0c0; background-color: #ffffff; } </style> <script type="text/javascript"> // // Tab Script created by Baris Wanschers // Contact: barisart@gmail.com // blog: www.bariswanschers.com // $(function () { var tabContainers = $('div#tabs > .tabbedWindow'); tabContainers.hide().filter('#tab-1').show(); $('div#tabs ul.tabNavigation a').click(function () { tabContainers.hide(); tabContainers.filter(this.hash).show(); $('div#tabs ul.tabNavigation a').removeClass('ms-topnavselected selected'); $(this).addClass('ms-topnavselected selected'); return false; }).filter('#tab-1').click(); }); </script> </asp:Content> <asp:Content runat="server" ContentPlaceHolderID="PlaceHolderMain"> <WebPartPages:SPProxyWebPartManager runat="server" id="ProxyWebPartManager"></WebPartPages:SPProxyWebPartManager> <div> <WebPartPages:WebPartZone id="g_B58E8EF48D294A6E89B2B1C44C554B4E" runat="server" title="Zone 2"><ZoneTemplate></ZoneTemplate></WebPartPages:WebPartZone><br></div> <table cellpadding="4" cellspacing="0" border="0" > <tr> <td id="_invisibleIfEmpty" name="_invisibleIfEmpty" valign="top" rowspan="5" style="width: 350px"> <WebPartPages:WebPartZone id="g_3F895C6E6999454A81F47069167554B8" runat="server" title="Zone 1"><ZoneTemplate></ZoneTemplate></WebPartPages:WebPartZone> </td> <td id="_invisibleIfEmpty" name="_invisibleIfEmpty" valign="top" rowspan="5"> </td> <td id="_invisibleIfEmpty" name="_invisibleIfEmpty" valign="top" style="width: 100%" > <WebPartPages:WebPartZone runat="server" Title="loc:Header" ID="Header" FrameType="TitleBarOnly"><ZoneTemplate></ZoneTemplate></WebPartPages:WebPartZone> </td> </tr> <tr> <td id="_invisibleIfEmpty" name="_invisibleIfEmpty" valign="top" style="width: 100%"> <table style="width: 100%" cellpadding="0" cellspacing="0" class="style1"> <tr> <td valign="top"> <WebPartPages:WebPartZone runat="server" Title="loc:Tab" ID="g_E73F3DE86242404C8B54E2684B809633"><ZoneTemplate> <WebPartPages:ContentEditorWebPart runat="server" __MarkupType="xmlmarkup" WebPart="true" __WebPartId="{7D4FD124-D9F3-417C-A0AB-529C4C8E76BF}" > <WebPart xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.microsoft.com/WebPart/v2"> <Title>Tabs</Title> <FrameType>None</FrameType> <Description>Use for formatted text, tables, and images.</Description> <IsIncluded>true</IsIncluded> <PartOrder>1</PartOrder> <FrameState>Normal</FrameState> <Height /> <Width /> <AllowRemove>true</AllowRemove> <AllowZoneChange>true</AllowZoneChange> <AllowMinimize>true</AllowMinimize> <AllowConnect>true</AllowConnect> <AllowEdit>true</AllowEdit> <AllowHide>true</AllowHide> <IsVisible>true</IsVisible> <DetailLink /> <HelpLink /> <HelpMode>Modeless</HelpMode> <Dir>Default</Dir> <PartImageSmall /> <MissingAssembly>Cannot import this Web Part.</MissingAssembly> <PartImageLarge>/_layouts/images/mscontl.gif</PartImageLarge> <IsIncludedFilter /> <ExportControlledProperties>true</ExportControlledProperties> <ConnectionID>00000000-0000-0000-0000-000000000000</ConnectionID> <ID>g_7d4fd124_d9f3_417c_a0ab_529c4c8e76bf</ID> <ContentLink xmlns="http://schemas.microsoft.com/WebPart/v2/ContentEditor" /> <Content xmlns="http://schemas.microsoft.com/WebPart/v2/ContentEditor"><![CDATA[<script type="text/javascript"> <!-- Code to add Tabs (as "Content Web Part in SharePoint") --> <div id="tabs"> <ul id="tabs" class="tabNavigation ms-WPBody"> <li><a href="#tab-1" class="selected ms-topnavselected"><span>TAB 1</span></a></li> <li><a href="#tab-2" ><span>TAB 2</span></a></li> <li><a href="#tab-3" ><span>TAB 3</span></a></li> <li><a href="#tab-4" ><span>TAB 4</span></a></li> <li><a href="#tab-5" ><span>TAB 5</span></a></li> <li><a href="#tab-6" ><span>TAB 6</span></a></li> <li><a href="#tab-7" ><span>TAB 7</span></a></li> </ul> </div> ]]></Content> <PartStorage xmlns="http://schemas.microsoft.com/WebPart/v2/ContentEditor" /> </WebPart> </WebPartPages:ContentEditorWebPart> </ZoneTemplate></WebPartPages:WebPartZone> </td> </tr> </table> </td> </tr> <tr> <td id="_invisibleIfEmpty" name="_invisibleIfEmpty" valign="top" height="100%" style="width: 100%"> <div id="tabs"> <div class="tabbedWindow" id="tab-1"> <table style="width: 100%" cellpadding="0" cellspacing="0" class="style1"> <tr> <td colspan="3"> <WebPartPages:WebPartZone id="g_D136027997C140AEA0E6325982283B91" runat="server" title="Zone Tab 1"><ZoneTemplate></ZoneTemplate></WebPartPages:WebPartZone> </td> </tr> <tr> <td valign="top"> <WebPartPages:WebPartZone id="g_42C56BB11DD145109FD6B8B37FE5F418" runat="server" title="Zone Tab 1 Left"><ZoneTemplate></ZoneTemplate></WebPartPages:WebPartZone> </td> <td valign="top"> </td> <td valign="top"> <WebPartPages:WebPartZone id="g_A7DCA0FC58D949B299E3A8C06A74B90B" runat="server" title="Zone Tab 1 Right"><ZoneTemplate></ZoneTemplate></WebPartPages:WebPartZone> </td> </tr> </table> </div> <div class="tabbedWindow" id="tab-2"> <table style="width: 100%" cellpadding="0" cellspacing="0" class="style1"> <tr> <td colspan="3"> <WebPartPages:WebPartZone id="g_0DD3E4CF951141A58CB427747F47B020" runat="server" title="Zone Tab 2"><ZoneTemplate></ZoneTemplate></WebPartPages:WebPartZone> </td> </tr> <tr> <td> <WebPartPages:WebPartZone id="g_C728594D0AF244AABC2512C10D4296CD" runat="server" title="Zone Tab 2 Left"><ZoneTemplate></ZoneTemplate></WebPartPages:WebPartZone> </td> <td valign="top"> </td> <td valign="top"> <WebPartPages:WebPartZone id="g_5D8954458817443ABD45967AEE5937EB" runat="server" title="Zone Tab 2 Right"><ZoneTemplate></ZoneTemplate></WebPartPages:WebPartZone> </td> </tr> </table> </div> <div class="tabbedWindow" id="tab-3"> <WebPartPages:WebPartZone id="ID3" runat="server" title="Zone Tab 3"><ZoneTemplate></ZoneTemplate></WebPartPages:WebPartZone> <table style="width: 100%" cellpadding="0" cellspacing="0" class="style1"> <tr> <td> <WebPartPages:WebPartZone id="g_E66154B9A0F444168B80124928A60AF1" runat="server" title="Zone Tab 3 Left"><ZoneTemplate></ZoneTemplate></WebPartPages:WebPartZone> </td> <td valign="top"> </td> <td valign="top"> <WebPartPages:WebPartZone id="g_96EE7CAE5037494ABB0F62F67AFACD88" runat="server" title="Zone Tab 3 Right"><ZoneTemplate></ZoneTemplate></WebPartPages:WebPartZone> </td> </tr> </table> </div> <div class="tabbedWindow" id="tab-4"> <WebPartPages:WebPartZone id="ID4" runat="server" title="Zone Tab 4"><ZoneTemplate></ZoneTemplate></WebPartPages:WebPartZone> <table style="width: 100%" cellpadding="0" cellspacing="0" class="style1"> <tr> <td> <WebPartPages:WebPartZone id="g_25E5C41FE1104ACB8E9F6B73D1730F0F" runat="server" title="Zone Tab 4 Left"><ZoneTemplate></ZoneTemplate></WebPartPages:WebPartZone> </td> <td valign="top"> </td> <td valign="top"> <WebPartPages:WebPartZone id="g_76986E4A98F04D0397A26136C3196545" runat="server" title="Zone Tab 4 Right"><ZoneTemplate></ZoneTemplate></WebPartPages:WebPartZone> </td> </tr> </table> </div> <div class="tabbedWindow" id="tab-5"> <WebPartPages:WebPartZone id="ID5" runat="server" title="Zone Tab 5"><ZoneTemplate></ZoneTemplate></WebPartPages:WebPartZone> <table style="width: 100%" cellpadding="0" cellspacing="0" class="style1"> <tr> <td> <WebPartPages:WebPartZone id="g_182F371C67C0444B842B36F8644B6635" runat="server" title="Zone Tab 5 Left"><ZoneTemplate></ZoneTemplate></WebPartPages:WebPartZone> </td> <td valign="top"> </td> <td valign="top"> <WebPartPages:WebPartZone id="g_008D3B4587D647D285A758126D40F374" runat="server" title="Zone Tab 5 Right"><ZoneTemplate></ZoneTemplate></WebPartPages:WebPartZone> </td> </tr> </table> </div> <div class="tabbedWindow" id="tab-6"> <WebPartPages:WebPartZone id="ID6" runat="server" title="Zone Tab 6"><ZoneTemplate></ZoneTemplate></WebPartPages:WebPartZone> <table style="width: 100%" cellpadding="0" cellspacing="0" class="style1"> <tr> <td> <WebPartPages:WebPartZone id="g_313569A6112341E4B6628B6649E830A6" runat="server" title="Zone Tab 6 Left"><ZoneTemplate></ZoneTemplate></WebPartPages:WebPartZone> </td> <td valign="top"> </td> <td valign="top"> <WebPartPages:WebPartZone id="g_9BC67554017E4AE0A2711AC6C2F03040" runat="server" title="Zone Tab 6 Right"><ZoneTemplate></ZoneTemplate></WebPartPages:WebPartZone> </td> </tr> </table> </div> <div class="tabbedWindow" id="tab-7"> <WebPartPages:WebPartZone id="ID7" runat="server" title="Zone Tab 7"><ZoneTemplate></ZoneTemplate></WebPartPages:WebPartZone> <table style="width: 100%" cellpadding="0" cellspacing="0" class="style1"> <tr> <td> <WebPartPages:WebPartZone id="g_6981A4726C7448AC953D55D0A4C5A16C" runat="server" title="Zone Tab 7 Left"><ZoneTemplate></ZoneTemplate></WebPartPages:WebPartZone> </td> <td valign="top"> </td> <td valign="top"> <WebPartPages:WebPartZone id="g_CE1F6BAE1B75441CABDD536DC155274C" runat="server" title="Zone Tab 7 Right"><ZoneTemplate></ZoneTemplate></WebPartPages:WebPartZone> </td> </tr> </table> </div> <div class="tabbedWindow" id="tab-8"> <WebPartPages:WebPartZone id="ID8" runat="server" title="Zone Tab 8"><ZoneTemplate></ZoneTemplate></WebPartPages:WebPartZone> <table style="width: 100%" cellpadding="0" cellspacing="0" class="style1"> <tr> <td> <WebPartPages:WebPartZone id="g_4EB47EF0353A44339413DC9F4FA341CC" runat="server" title="Zone Tab 8 Left"><ZoneTemplate></ZoneTemplate></WebPartPages:WebPartZone> </td> <td valign="top"> </td> <td valign="top"> <WebPartPages:WebPartZone id="g_645A1348A1184895BEFFFCD0931C972D" runat="server" title="Zone Tab 8 Right"><ZoneTemplate></ZoneTemplate></WebPartPages:WebPartZone> </td> </tr> </table> </div> <div class="waste"></div> </div> </td> </tr> <tr> <td id="_invisibleIfEmpty" name="_invisibleIfEmpty" valign="top" style="width: 100%"> <WebPartPages:WebPartZone runat="server" Title="loc:Content_Visible_On_All_Tabs" ID="Footer" FrameType="TitleBarOnly"><ZoneTemplate></ZoneTemplate></WebPartPages:WebPartZone> </td> </tr> <script language="javascript">if(typeof(MSOLayout_MakeInvisibleIfEmpty) == "function") {MSOLayout_MakeInvisibleIfEmpty();}</script> </table> </asp:Content> <asp:Content runat="server" ContentPlaceHolderID="PlaceHolderPageTitle"> Site </asp:Content> [ICODE] Ok, so if you navigate ovr to my website "http://www.mancunianmacca.co.cc" you will notice that a box pops up asking for your name. When you type it in it adds it to the page. Is there a way I can get this to remember the users input and only ask them once then remember. Like cookie or anything. If you need any extra things. Just ask.
I have a JavaScript that remembers the values of a form by creating cookies for each input element onblur. I cannot figure out though how to exclude one input field from being remember. It would be document.getElementsByTagName('input')[15] Every time I try to add an if/else statement in using that line, the script doesn't work altogether. Code: window.onload = function() { rememberFormInputs('rma', 'input-'); } /** * Set a cookie * @param string cookie name * @param string cookie value * @param string cookie expiration counter in days * @param string cookie path * @param string cookie domain * @param bool secure? */ function setCookie(name, value, expires, path, domain, secure) { var today = new Date(); today.setTime(today.getTime()); if (expires) { expires = expires * 1000 * 60 * 60 * 24; } var expires_date = new Date(today.getTime() + (expires)); document.cookie = name+"="+escape(value) + ((expires) ? ";expires="+expires_date.toGMTString() : "") + ((path) ? ";path=" + path : "") + ((domain) ? ";domain=" + domain : "") + ((secure) ? ";secure" : ""); } /** * Get a cookie value * @param string cookie name */ function getCookie(name) { var start = document.cookie.indexOf(name + "="); var len = start + name.length + 1; if ((!start) && (name != document.cookie.substring(0, name.length))) { return null; } if (start == -1) return null; var end = document.cookie.indexOf(";", len); if (end == -1) end = document.cookie.length; return unescape(document.cookie.substring(len, end)); } /** * Remebers form inputs after you fill them in * @param string form id to remember fields * @param string a prefix to prepend to all cookie names. (prevent naming conflicts) */ function rememberFormInputs(form_id, prefix) { var form = document.getElementById(form_id); var els = document.getElementsByTagName('input'); for (var i = 0; i < els.length; i++) { var el = els.item(i); if (el.type == 'text') { el.onblur = function() { var name = this.name; var value = this.value; setCookie(prefix + name, value, 90); }; var old_value = getCookie(prefix + el.name); if (old_value && old_value != '') { el.value = old_value; } } } } Does anyone have a solution? I would really appreciate it :] Hi im new to working with cookies so would appreaciate a little help I using the w3c tuturial as a template so heres a link so you can see what im trying to do http://www.w3schools.com/JS/js_cookies.asp Code: function getCookie(c_name) { var i,x,y,ARRcookies=document.cookie.split(";"); for (i=0;i<ARRcookies.length;i++) { x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("=")); y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1); x=x.replace(/^\s+|\s+$/g,""); if (x==c_name) { return unescape(y); } } } function setCookie(c_name,value,exdays) { var exdate=new Date(); exdate.setDate(exdate.getDate() + exdays); var c_value=escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString()); document.cookie=c_name + "=" + c_value; } function checkCookie(username) { var username=getCookie("username"); if (username!=null && username!="") { document.getElementById("feedback").innerHTML = " last time you scored " + username); setCookie("username",username,365); } else { if (username=null || username="") { setCookie("username",username,365); } } } I kept the variable names the same so you can follow and I don't confuse myself and make things more complected while im trying to debug it. Some extra information. checkcookie is been given a variable it is just a simple number. Im making a questionnaire which is done but I wont the top of the page to tell the user how much they scored last or tell them this is their first time trying it. The variable being passed to check cookie is their score . at the moment when I click the submit button nothing happens. Where it should trigger a score calculating function which should then call the checkcookie function while passing the score it calculated. I would love if someone can point me in the right direction or help me correct it or atleast explain to me whats going wrong. Thanks and a lots of appreciation if anyone can spare the time 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 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! 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 Hi i used cookies to store data using java script with 2 calculators, but there is a 3rd calculator that the cookies arent storing, can someone help me figure out where to implement the script?
I am running a vBulletin and am using a script to set a cookie each time someone clicks a banner. When the user then reloads the page it looks for that cookie and hides the banner if the cookie exists. I now want to write the date into the cookie name so that the cookie name changes every day. I want to do this because for some reason the cookie gets re-written sometimes and never expires. Because of vBulletin and Firefox I have to use PHP to check initially if the cookie is even set. Here is my current script, any help would be appreciated. Code: <?PHP if( isset( $_COOKIE['noads139'] ) ) { } else { ?> <script type="text/javascript"> function as_click () { myDate = new Date(); myDate.setTime(myDate.getTime()+(1*24*60*60*1000)); document.cookie = 'noads139=noads139; expires=' + myDate.toGMTString()+"; path=/" } // incredibly funky onload add-event scripting, for all browsers if(typeof window.addEventListener != 'undefined') { //.. gecko, safari, konqueror and standard window.addEventListener('load', adsense_init, false); } else if(typeof document.addEventListener != 'undefined') { //.. opera 7 document.addEventListener('load', adsense_init, false); } else if(typeof window.attachEvent != 'undefined') { //.. win/ie window.attachEvent('onload', adsense_init); } //** remove this condition to degrade older browsers else { //.. mobile safari, mac/ie5 and anything else that gets this far //if there's an existing onload function if(typeof window.onload == 'function') { //store it var existing = onload; //add new onload handler window.onload = function() { //call existing onload function existing(); //call adsense_init onload function adsense_init(); }; } else { //setup onload function window.onload = adsense_init; } } function adsense_init () { if (document.all) { //ie var el = document.getElementsByTagName("iframe"); for(var i = 0; i < el.length; i++) { if(el[i].src.indexOf('googlesyndication.com') > -1) { el[i].onfocus = as_click; } } } else { // firefox window.addEventListener('beforeunload', doPageExit, false); window.addEventListener('mousemove', getMouse, true); } } //for firefox var px; var py; function getMouse(e) { px=e.pageX; py=e.pageY; } function findY(obj) { var y = 0; while (obj) { y += obj.offsetTop; obj = obj.offsetParent; } return(y); } function findX(obj) { var x = 0; while (obj) { x += obj.offsetLeft; obj = obj.offsetParent; } return(x); } function doPageExit(e) { ad = document.getElementsByTagName("iframe"); for (i=0; i<ad.length; i++) { var adLeft = findX(ad[i]); var adTop = findY(ad[i]); var inFrameX = (px > (adLeft - 10) && px < (parseInt(adLeft) + parseInt(ad[i].width) + 15)); var inFrameY = (py > (adTop - 10) && py < (parseInt(adTop) + parseInt(ad[i].height) + 10)); if (inFrameY && inFrameX) { myDate = new Date(); myDate.setTime(myDate.getTime()+(1*24*60*60*1000)); document.cookie = 'noads139=noads139; expires=' + myDate.toGMTString()+"; path=/" } } } //end for firefox </script> <?PHP } ?> <div id="adsense" style="display: none"> <script type="text/javascript"><!-- google_ad_client = "pub-xxxxxxxxxxxxxxx"; /* 728x90, created 4/15/10 */ google_ad_slot = "xxxxxxxxxxxxxx"; google_ad_width = 728; google_ad_height = 90; //--> </script> <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script> </div> <script type="text/javascript"> if (document.cookie.indexOf('noads139') < 0) { document.getElementById('adsense').style.display = ''; } else { } </script> <script type="text/javascript"> if((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i)) || (navigator.userAgent.match(/iPad/i))) { document.getElementById('adsense').style.display = 'none'; } else { } </script> I have a script that sets a cookie for the user selected stylesheet, however I want to be able to clear the cookie it sets. How can this be accomplished? Code: //Style Sheet Switcher version 1.1 Oct 10th, 2006 //Author: Dynamic Drive: http://www.dynamicdrive.com //Usage terms: http://www.dynamicdrive.com/notice.htm var manual_or_random="manual" //"manual" or "random" var randomsetting="3 days" //"eachtime", "sessiononly", or "x days (replace x with desired integer)". Only applicable if mode is random. //////No need to edit beyond here////////////// function getCookie(Name) { var re=new RegExp(Name+"=[^;]+", "i"); //construct RE to search for target name/value pair if (document.cookie.match(re)) //if cookie found return document.cookie.match(re)[0].split("=")[1] //return its value return null } function setCookie(name, value, days) { var expireDate = new Date() //set "expstring" to either future or past date, to set or delete cookie, respectively var expstring=(typeof days!="undefined")? expireDate.setDate(expireDate.getDate()+parseInt(days)) : expireDate.setDate(expireDate.getDate()-5) document.cookie = name+"="+value+"; expires="+expireDate.toUTCString()+"; path=/"; } function deleteCookie(name){ setCookie(name, "moot") } function setStylesheet(title, randomize){ //Main stylesheet switcher function. Second parameter if defined causes a random alternate stylesheet (including none) to be enabled var i, cacheobj, altsheets=[""] for(i=0; (cacheobj=document.getElementsByTagName("link")[i]); i++) { if(cacheobj.getAttribute("rel").toLowerCase()=="alternate stylesheet" && cacheobj.getAttribute("title")) { //if this is an alternate stylesheet with title cacheobj.disabled = true altsheets.push(cacheobj) //store reference to alt stylesheets inside array if(cacheobj.getAttribute("title") == title) //enable alternate stylesheet with title that matches parameter cacheobj.disabled = false //enable chosen style sheet } } if (typeof randomize!="undefined"){ //if second paramter is defined, randomly enable an alt style sheet (includes non) var randomnumber=Math.floor(Math.random()*altsheets.length) altsheets[randomnumber].disabled=false } return (typeof randomize!="undefined" && altsheets[randomnumber]!="")? altsheets[randomnumber].getAttribute("title") : "" //if in "random" mode, return "title" of randomly enabled alt stylesheet } function chooseStyle(styletitle, days){ //Interface function to switch style sheets plus save "title" attr of selected stylesheet to cookie if (document.getElementById){ setStylesheet(styletitle) setCookie("mysheet", styletitle, days) } } function indicateSelected(element){ //Optional function that shows which style sheet is currently selected within group of radio buttons or select menu if (selectedtitle!=null && (element.type==undefined || element.type=="select-one")){ //if element is a radio button or select menu var element=(element.type=="select-one") ? element.options : element for (var i=0; i<element.length; i++){ if (element[i].value==selectedtitle){ //if match found between form element value and cookie value if (element[i].tagName=="OPTION") //if this is a select menu element[i].selected=true else //else if it's a radio button element[i].checked=true break } } } } if (manual_or_random=="manual"){ //IF MANUAL MODE var selectedtitle=getCookie("mysheet") if (document.getElementById && selectedtitle!=null) //load user chosen style sheet from cookie if there is one stored setStylesheet(selectedtitle) } else if (manual_or_random=="random"){ //IF AUTO RANDOM MODE if (randomsetting=="eachtime") setStylesheet("", "random") else if (randomsetting=="sessiononly"){ //if "sessiononly" setting if (getCookie("mysheet_s")==null) //if "mysheet_s" session cookie is empty document.cookie="mysheet_s="+setStylesheet("", "random")+"; path=/" //activate random alt stylesheet while remembering its "title" value else setStylesheet(getCookie("mysheet_s")) //just activate random alt stylesheet stored in cookie } else if (randomsetting.search(/^[1-9]+ days/i)!=-1){ //if "x days" setting if (getCookie("mysheet_r")==null || parseInt(getCookie("mysheet_r_days"))!=parseInt(randomsetting)){ //if "mysheet_r" cookie is empty or admin has changed number of days to persist in "x days" variable setCookie("mysheet_r", setStylesheet("", "random"), parseInt(randomsetting)) //activate random alt stylesheet while remembering its "title" value setCookie("mysheet_r_days", randomsetting, parseInt(randomsetting)) //Also remember the number of days to persist per the "x days" variable } else setStylesheet(getCookie("mysheet_r")) //just activate random alt stylesheet stored in cookie } } |