JavaScript - Adjusting Cookie
Hey all,
I have set up a cookie that redirects the visitor if they have visited the page before. However, I'd like to make some adjustments to it to where if they have cookies turned off, it automatically redirects them to a page that requests them to turn on cookies. Any ideas? Code: <script> num_days = 24; function ged(noDays){ var today = new Date(); var expr = new Date(today.getTime() + noDays*60*60*1000); return expr.toGMTString(); } function readCookie(cookieName){ var start = document.cookie.indexOf(cookieName); if (start == -1){ document.cookie = "seenit=yes; expires=" + ged(num_days); } else { window.location = go_to; } } var go_to = "/index.php?module=article&id=310"; readCookie("seenit"); </script> Similar TutorialsHi 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, I currently have a SLN file which need's adjusting slightly. Please could someone help me adjust this code in this file http://www.2shared.com/file/7072761/...nal_csf11.html From : Sr.WriteLine("Cars = UF1"); To : Sr.WriteLine("Cars = XFG"); Thanks Matty Problem Solved
Hi I have this snippet of code which shows an image based on what radio button is selected, problem is that the names, id's, values etc are dynamically created via the admin panel of my cart so what happens is that the buttons are not recognised as being 'checked' if I make them 'checked'... I can sort of see where its trying to check if 'checked' but quite sure how to make it suit my radio button without changing the buttons id's. here my code: Code: <div id="Tabdoc_content3" class="Tabdoc_tabdivcontent" style="background-image:url('/images/back-sweets.png');background-repeat:no-repeat;background-position:center bottom;background-size:100%;" > <div class="wrapperAttribsOptions"> <table width="100%" cellspacing="0" cellpadding="0" border="0"> <tr valign="top"> <td> <script language="javascript"> function toggle1(showHideDiv, switchImgTag) { var ele = document.getElementById(showHideDiv); var imageEle = document.getElementById(switchImgTag); if(ele.style.display == "block") { ele.style.display = "none"; imageEle.innerHTML = '<img src="/images/tabs/button_open_sweet1.gif">'; } else { ele.style.display = "block"; imageEle.innerHTML = '<img src="/images/tabs/button_close_sweet1.gif">'; } } function toggle2(showHideDiv, switchImgTag) { var ele2 = document.getElementById(showHideDiv); var imageEle2 = document.getElementById(switchImgTag); if(ele2.style.display == "block") { ele2.style.display = "none"; imageEle2.innerHTML = '<img src="/images/tabs/button_open_sweet2.gif">'; } else { ele2.style.display = "block"; imageEle2.innerHTML = '<img src="/images/tabs/button_close_sweet2.gif">'; } } function toggle3(showHideDiv, switchImgTag) { var ele3 = document.getElementById(showHideDiv); var imageEle3 = document.getElementById(switchImgTag); if(ele3.style.display == "block") { ele3.style.display = "none"; imageEle3.innerHTML = '<img src="/images/tabs/button_open_sweet3.gif">'; } else { ele3.style.display = "block"; imageEle3.innerHTML = '<img src="/images/tabs/button_close_sweet3.gif">'; } } </script> <table cellpadding="0" cellspacing="0" border="0" width="100%"> <tr valign="top"> <td align="center" width="33%"> <script type="text/javascript"> // For: http://www.codingforums.com/showthread.php?p=1107835#post1107835 var picFile0 = ['sweet1.png','sweet2.png','sweet3.png','sweet4.png','sweet5.png','sweet6.png','sweet7.png','sweet8.png','sweet9.png','sweet10.png','sweet11.png','sweet12.png','sweet13.png','sweet14.png','sweet15.png','sweet16.png','sweet17.png','sweet18.png']; // each can be expanded with more images var picFile1 = ['sweet1.png','sweet2.png','sweet3.png','sweet4.png','sweet5.png','sweet6.png','sweet7.png','sweet8.png','sweet9.png','sweet10.png','sweet11.png','sweet12.png','sweet13.png','sweet14.png','sweet15.png','sweet16.png','sweet17.png','sweet18.png']; var picFile2 = ['sweet1.png','sweet2.png','sweet3.png','sweet4.png','sweet5.png','sweet6.png','sweet7.png','sweet8.png','sweet9.png','sweet10.png','sweet11.png','sweet12.png','sweet13.png','sweet14.png','sweet15.png','sweet16.png','sweet17.png','sweet18.png']; var imgPtr = [ // [current_image,baseURL,filenames,display_image] [0,"/images/tabs/",'imgSrc0'], [0,"/images/tabs/",'imgSrc1'], [0,"/images/tabs/",'imgSrc2'] // No comma after last entry ]; // Create function to load image function loadImg(imgGroup) { var picFile = []; var imgID = imgPtr[imgGroup][2]; switch (imgGroup) { case '0' : picFile=[].concat(picFile0); break; case '1' : picFile=[].concat(picFile1); break; case '2' : picFile=[].concat(picFile2); break; default : alert('Invalid assignment\n'+imgGroup); break; } var ptr = imgPtr[imgGroup][0]; if (ptr < 0) { ptr = 0; } if (ptr > picFile.length-1) { ptr = picFile.length-1; } document.getElementById(imgID).src = imgPtr[imgGroup][1]+picFile[ptr]; imgPtr[imgGroup][0] = ptr; var rbtn = 'rg'+imgGroup+ptr; // alert(rbtn); document.getElementById(rbtn).checked = true; } // Create link function to switch image backward function prev(imgGroup) { imgPtr[imgGroup][0]--; loadImg(imgGroup); } // Create link function to switch image forward function next(imgGroup){ imgPtr[imgGroup][0]++; loadImg(imgGroup); } // Load function after page loads onload = function() { loadImg('0'); loadImg('1'); loadImg('2'); } </script> <div style="width:230px;text-align:center;"> <img name="imgSrc0" id="imgSrc0" src="/images/tabs/sweet1.png"> </div> <div id="headerDivImg"> <div id="titleTextImg"></div> <a id="imageDivLink" href="javascript:toggle1('contentDivImg', 'imageDivLink');"> <img src="/images/tabs/button_open_sweet1.gif"></a> </div> <div id="contentDivImg" class="sweetlist" style="display: none;"> <p>BOILED SWEETS - STANDARD</p> <input name="id[18]" value="81" id="attrib-18-81" type="radio" onclick="imgPtr[0][0]=12;loadImg('0')"><label class="attribsRadioButton zero" for="attrib-18-81"> Kola Cubes</label><br /> <input name="id[18]" value="82" id="attrib-18-82" type="radio" onclick="imgPtr[0][0]=13;loadImg('0')"><label class="attribsRadioButton zero" for="attrib-18-82"> Pineapple Cubes</label><br /> <input name="id[18]" value="79" id="attrib-18-79" type="radio" onclick="imgPtr[0][0]=10;loadImg('0')"><label class="attribsRadioButton zero" for="attrib-18-79"> Rhubarb and Custard</label><br /> <input name="id[18]" value="80" id="attrib-18-80" type="radio" onclick="imgPtr[0][0]=11;loadImg('0')"><label class="attribsRadioButton zero" for="attrib-18-80"> Strawberry and Cream</label><br /><br /> <p>BOILED SWEETS - SPECIAL</p> <input name="id[18]" value="76" id="attrib-18-76" type="radio" onclick="imgPtr[0][0]=7;loadImg('0')"><label class="attribsRadioButton zero" for="attrib-18-76"> Fizzy Blueberry</label><br /> <input name="id[18]" value="61" checked="checked" id="attrib-18-61" type="radio" onclick="imgPtr[0][0]=0;loadImg('0')"><label class="attribsRadioButton zero" for="attrib-18-61"> Fruits of the Forest</label><br /> <input name="id[18]" value="74" id="attrib-18-74" type="radio" onclick="imgPtr[0][0]=5;loadImg('0')"><label class="attribsRadioButton zero" for="attrib-18-74"> Lemon and Lime</label><br /> <input name="id[18]" value="62" id="attrib-18-62" type="radio" onclick="imgPtr[0][0]=1;loadImg('0')"><label class="attribsRadioButton zero" for="attrib-18-62"> Pear Drops</label><br /> <input name="id[18]" value="77" id="attrib-18-77" type="radio" onclick="imgPtr[0][0]=8;loadImg('0')"><label class="attribsRadioButton zero" for="attrib-18-77"> Sour Cherry</label><br /> <input name="id[18]" value="73" id="attrib-18-73" type="radio" onclick="imgPtr[0][0]=4;loadImg('0')"><label class="attribsRadioButton zero" for="attrib-18-73"> Wild Strawberry</label><br /><br /> <p>GUMMY SWEETS - ORGANIC</p> <input name="id[18]" value="85" id="attrib-18-85" type="radio" onclick="imgPtr[0][0]=16;loadImg('0')"><label class="attribsRadioButton zero" for="attrib-18-85"> Organic Fruit Cocktail</label><br /> <input name="id[18]" value="86" id="attrib-18-86" type="radio" onclick="imgPtr[0][0]=17;loadImg('0')"><label class="attribsRadioButton zero" for="attrib-18-86"> Organic Jelly Bears</label><br /> <input name="id[18]" value="83" id="attrib-18-83" type="radio" onclick="imgPtr[0][0]=14;loadImg('0')"><label class="attribsRadioButton zero" for="attrib-18-83"> Organic Sour Worms</label><br /> <input name="id[18]" value="84" id="attrib-18-84" type="radio" onclick="imgPtr[0][0]=15;loadImg('0')"><label class="attribsRadioButton zero" for="attrib-18-84"> Organic Sugar Bears</label><br /> </div> </td> <td align="center" width="33%"> <div style="width:230px;text-align:center;"> <img name="imgSrc1" id="imgSrc1" src="/images/tabs/sweet14.png"> </div> <div id="headerDivImg2"> <div id="titleTextImg2"></div> <a id="imageDivLink2" href="javascript:toggle2('contentDivImg2', 'imageDivLink2');"><img src="/images/tabs/button_open_sweet2.gif"></a> </div> <div id="contentDivImg2" class="sweetlist" style="display: none;"> <p>BOILED SWEETS - STANDARD</p> <input name="id[19]" value="99" id="attrib-19-99" type="radio" onclick="imgPtr[1][0]=12;loadImg('1')"><label class="attribsRadioButton zero" for="attrib-19-99"> Kola Cubes</label><br /> <input name="id[19]" value="100" id="attrib-19-100" type="radio" onclick="imgPtr[1][0]=13;loadImg('1')" ><label class="attribsRadioButton zero" for="attrib-19-100"> Pineapple Cubes</label><br /> <input name="id[19]" value="97" id="attrib-19-97" type="radio" onclick="imgPtr[1][0]=10;loadImg('1')"><label class="attribsRadioButton zero" for="attrib-19-97"> Rhubarb and Custard</label><br /> <input name="id[19]" value="98" id="attrib-19-98" type="radio" onclick="imgPtr[1][0]=11;loadImg('1')"><label class="attribsRadioButton zero" for="attrib-19-98"> Strawberry and Cream</label><br /><br /> <p>BOILED SWEETS - SPECIAL</p> <input name="id[19]" value="94" id="attrib-19-94" type="radio" onclick="imgPtr[1][0]=7;loadImg('1')"><label class="attribsRadioButton zero" for="attrib-19-94"> Fizzy Blueberry</label><br /> <input name="id[19]" value="87" checked="checked" id="attrib-19-87" type="radio" onclick="imgPtr[1][0]=0;loadImg('1')"><label class="attribsRadioButton zero" for="attrib-19-87"> Fruits of the Forest</label><br /> <input name="id[19]" value="92" id="attrib-19-92" type="radio" onclick="imgPtr[1][0]=5;loadImg('1')"><label class="attribsRadioButton zero" for="attrib-19-92"> Lemon and Lime</label><br /> <input name="id[19]" value="88" id="attrib-19-88" type="radio" onclick="imgPtr[1][0]=1;loadImg('1')"><label class="attribsRadioButton zero" for="attrib-19-88"> Pear Drops</label><br /> <input name="id[19]" value="95" id="attrib-19-95" type="radio" onclick="imgPtr[1][0]=8;loadImg('1')"><label class="attribsRadioButton zero" for="attrib-19-95"> Sour Cherry</label><br /> <input name="id[19]" value="91" id="attrib-19-91" type="radio" onclick="imgPtr[1][0]=4;loadImg('1')"><label class="attribsRadioButton zero" for="attrib-19-91"> Wild Strawberry</label><br /><br /> <p>GUMMY SWEETS - ORGANIC</p> <input name="id[19]" value="103" id="attrib-19-103" type="radio" onclick="imgPtr[1][0]=16;loadImg('1')"><label class="attribsRadioButton zero" for="attrib-19-103"> Organic Fruit Cocktail</label><br /> <input name="id[19]" value="104" id="attrib-19-104" type="radio" onclick="imgPtr[1][0]=17;loadImg('1')"><label class="attribsRadioButton zero" for="attrib-19-104"> Organic Jelly Bears</label><br /> <input name="id[19]" value="101" id="attrib-19-101" type="radio" onclick="imgPtr[1][0]=14;loadImg('1')"><label class="attribsRadioButton zero" for="attrib-19-101"> Organic Sour Worms</label><br /> <input name="id[19]" value="102" id="attrib-19-102" type="radio" onclick="imgPtr[1][0]=15;loadImg('1')"><label class="attribsRadioButton zero" for="attrib-19-102"> Organic Sugar Bears</label><br /> </div> </td> <td align="center" width="33%"> <div style="width:230px;text-align:center;"> <img name="imgSrc2" id="imgSrc2" src="/images/tabs/sweet11.png"> </div> <div id="headerDivImg3"> <div id="titleTextImg3"></div> <a id="imageDivLink3" href="javascript:toggle3('contentDivImg3', 'imageDivLink3');"><img src="/images/tabs/button_open_sweet3.gif"></a> </div> <div id="contentDivImg3" class="sweetlist" style="display: none;"> <p>BOILED SWEETS - STANDARD</p> <input name="id[20]" value="117" id="attrib-20-117" type="radio" onclick="imgPtr[2][0]=12;loadImg('2')"><label class="attribsRadioButton zero" for="attrib-20-117"> Kola Cubes</label><br /> <input name="id[20]" value="118" id="attrib-20-118" type="radio" onclick="imgPtr[2][0]=13;loadImg('2')"><label class="attribsRadioButton zero" for="attrib-20-118"> Pineapple Cubes</label><br /> <input name="id[20]" value="115" id="attrib-20-115" type="radio" onclick="imgPtr[2][0]=10;loadImg('2')"><label class="attribsRadioButton zero" for="attrib-20-115"> Rhubarb and Custard</label><br /> <input name="id[20]" value="116" id="attrib-20-116" type="radio" onclick="imgPtr[2][0]=11;loadImg('2')"><label class="attribsRadioButton zero" for="attrib-20-116"> Strawberry and Cream</label><br /><br /> <p>BOILED SWEETS - SPECIAL</p> <input name="id[20]" value="112" id="attrib-20-112" type="radio" onclick="imgPtr[2][0]=7loadImg('2')"><label class="attribsRadioButton zero" for="attrib-20-112"> Fizzy Blueberry</label><br /> <input name="id[20]" value="105" checked="checked" id="attrib-20-105" type="radio" onclick="imgPtr[2][0]=0;loadImg('2')"><label class="attribsRadioButton zero" for="attrib-20-105"> Fruits of the Forest</label><br /> <input name="id[20]" value="110" id="attrib-20-110" type="radio" onclick="imgPtr[2][0]=5;loadImg('2')"><label class="attribsRadioButton zero" for="attrib-20-110"> Lemon and Lime</label><br /> <input name="id[20]" value="106" id="attrib-20-106" type="radio" onclick="imgPtr[2][0]=1;loadImg('2')"><label class="attribsRadioButton zero" for="attrib-20-106"> Pear Drops</label><br /> <input name="id[20]" value="113" id="attrib-20-113" type="radio" onclick="imgPtr[2][0]=8;loadImg('2')"><label class="attribsRadioButton zero" for="attrib-20-113"> Sour Cherry</label><br /> <input name="id[20]" value="109" id="attrib-20-109" type="radio" onclick="imgPtr[2][0]=4;loadImg('2')"><label class="attribsRadioButton zero" for="attrib-20-109"> Wild Strawberry</label><br /><br /> <p>GUMMY SWEETS - ORGANIC</p> <input name="id[20]" value="121" id="attrib-20-121" type="radio" onclick="imgPtr[2][0]=16;loadImg('2')"><label class="attribsRadioButton zero" for="attrib-20-121"> Organic Fruit Cocktail</label><br /> <input name="id[20]" value="122" id="attrib-20-122" type="radio" onclick="imgPtr[2][0]=17;loadImg('2')"><label class="attribsRadioButton zero" for="attrib-20-122"> Organic Jelly Bears</label><br /> <input name="id[20]" value="119" id="attrib-20-119" type="radio" onclick="imgPtr[2][0]=14;loadImg('2')"><label class="attribsRadioButton zero" for="attrib-20-119"> Organic Sour Worms</label><br /> <input name="id[20]" value="120" id="attrib-20-120" type="radio" onclick="imgPtr[2][0]=15;loadImg('2')"><label class="attribsRadioButton zero" for="attrib-20-120"> Organic Sugar Bears</label><br /> </div> </td> </tr> </table> <br class="clearboth" /> </td> </tr> </table> </div> <div class="forward Tabdoc_pointer" style="margin-top:20px;margin-right:20px;position:relative;z-index:99;"> <img src="images/tabs/button_continue.gif" alt="CONTINUE" onclick="Tabdoc_ManageDisplay(4)"> </div> <div class="back Tabdoc_pointer" style="margin-top:20px;margin-left:20px;position:relative;z-index:99;"> <img src="images/tabs/button_back.gif" alt="BACK" onclick="Tabdoc_ManageDisplay(2)"> </div> <div class="clearboth"> <img src="images/back-sweets.png" alt=" " style="width:970px;margin:-71px 0 0 0;"/> </div> </div> The part I think is the problem is: Code: var rbtn = 'rg'+imgGroup+ptr; // alert(rbtn); document.getElementById(rbtn).checked = true; P.S. Sorry about the mixture of 'divs' and 'tables', i'm still sorting out the styling. P.S.S. If you need a visual representation please PM me and I will send you link I have dealt with window open before and i know how to adjust the size of the window in the parameters assigned but i have never dealt with window.opener before and have had several failed attempts and adjusting the window size here.. any help would be appreciated.. there is some inline css that i can change the background and stuff but i tried using height and width in the css to no avail, so i thought i would ask do i need to assign a new var inside the script ? how do i change the size. ? it needs to be 300x300 thanks Code: <script language="JavaScript"> var host = '<?php echo $_SERVER['HTTP_HOST'];?>'; var win = false; if (window.opener) { win=window.opener; } else if (top.document) { win=top.document; } if (!win || win.location.href.toString().indexOf('<?php echo $parent_href;?>')==-1) { window.location.href = '<?php echo $parent_href;?>'; } I have a javascript sound board that I've made for a Church skit but I'm wanting to be able to smoothly fade out the longer SFX without having to do it manually with the volume slider. The Object: Code: <span id="player_holder"><embed id="player" hidden="true" autostart="true" loop="false" volume="100"/></span> How do I modify the volume value from: Code: document.getElementById('player') Any ideas? Hi, I have a search function which works when I only want to have only one search per page, but as it involves a string call I'm not sure how to modify it to multiple search requests on a page. The below works fine for one call: Code: <script type="text/javascript"> function showHint(str){ if (str.length==0){ document.getElementById("txtHint").innerHTML=""; return; } if (window.XMLHttpRequest){ xmlhttp=new XMLHttpRequest(); } else{ xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange=function(){ if (xmlhttp.readyState==4 && xmlhttp.status==200){ document.getElementById("txtHint").innerHTML=xmlhttp.responseText; } } xmlhttp.open("GET","getName.php?q="+str,true); xmlhttp.send(); } </script> </head> <body> <label>Search by name: </label> <input type="text" id="txt1" class="input" onkeyup="showHint(this.value)" /> <br /> <p>Suggestions: <span id="txtHint"></span></p> <br /> But if I want to do mulitple I have tried changing it to: Code: <script type="text/javascript"> function showHint(File,ID){ if (str.length==0){ document.getElementById(ID).innerHTML=""; return; } if (window.XMLHttpRequest){ xmlhttp=new XMLHttpRequest(); } else{ xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange=function(){ if (xmlhttp.readyState==4 && xmlhttp.status==200){ document.getElementById(ID).innerHTML=xmlhttp.responseText; } } xmlhttp.open("GET",File,true); xmlhttp.send(); } </script> </head> <body> <label>Search by firstname: </label> <input type="text" id="txt1" class="input" onkeyup="showHint('GetFirstName.php?q='+str,'txtHint')" /> <br /> <p>Suggestions: <span id="txtHint"></span></p> <br /> <label>Search by surname: </label> <input type="text" id="txt1" class="input" onkeyup="showHint('getLastName.php?q='+str,'txtHintSn')" /> <br /> <p>Suggestions: <span id="txtHintSn"></span></p> <br /> The above doesn't work and I am not sure what do about the showHint(str) as clearly I am not representing it properly in my attempt to modify the script. I'm still struggling for a solution here. I have a background image that auto-resizes based on browser window / screen resolution. I want my top header menu, which requires links, to act in the same way and be in roughly the same position/size based on browser window. Is this possible? In the sample below, the image is just part of the background image to give you an idea of the look I am trying to duplicate. Is there a Javascript out there that will help me or will I be stuck having to rework my design? http://www.uberbotjones.com/sanny/test.html This site is really driving me crazy. 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 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 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 all, I need some help here. I'm new to HTML 5 and I'm not sure how to convert my cookie script over to HTML 5 LocalStorage. If anyone could help, I would appreciate it greatly. Here's my cookie script: Code: var currentRotation=null; function checkOrientAndLocation(){ if(currentRotation != window.orientation){ setOrientation(); } } function setOrientation(){ switch(window.orientation){ case 0: orient = 'portrait'; break; case 90: orient = 'landscape'; break; case -90: orient = 'landscape'; break; } currentRotation = window.orientation; document.body.setAttribute("orient",orient); setTimeout(scrollTo,0,0,1); } $(window).unload(function() { // On page unload $('.remember').each(function() { // Save each value to expire in a year $.cookie(this.id, this.value, {expires: 365}); }); $('.draggable').each(function() { // Save draggable positions var draggable = $(this); $.cookie(this.id, draggable.css('top') + '_' + draggable.css('left'), {expires: 365}); $.cookie('disp' + this.id, draggable.css('display'), {expires: 365}); }); }); $(function() { var val, pos, disp; setInterval(checkOrientAndLocation,1000); $('.remember').each(function() { var val = $.cookie(this.id); // Retrieve value for this element if (val) { this.value = val; } } ); $('.draggable').each(function() { var pos = $.cookie(this.id); // Retrieve values for this element if (pos) { pos = pos.split('_'); $(this).css({position: 'absolute', top: pos[0], left: pos[1]}); } var disp = $.cookie('disp' + this.id); if (disp) { this.style.display = disp; } } ).touch({animate: false, sticky: false, dragx: true, dragy: true, rotate: false, resort: false, scale: false }); }); I cannot get the cookie to save, I'm pretty new at web designing in general. If you could, the name of the cookie be cirulcook, also any advice you would have for me would be great! Code: <script><!-- function SETcookie(){ document.cookie="Selected="+document.getElementById('myList').selectedIndex; } function GETcookie(){ if (document.cookie){ eval(document.cookie); document.getElementById('myList').selectedIndex=Selected; }}// --></script> </head> <body onLoad="GETcookie()"> <select id="myList" onChange="SETcookie()"> <option value="1">Option 1</option> <option value="2">Option 2</option> <option value="3">Option 3</option> <option value="4">Option 4</option> </select> Hello, I was wondering if someone could tell me how to change the cookie on this piece of code? I'd like it to put a different cookie for each page it's used on. Any help would be appreciated. Thanks! Code: /* * COOKIE FUNCTIONS */ function createCookie(name, value, days) { if (days) { var date = new Date(); date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000)); var expires = "; expires=" + date.toGMTString(); } else var expires = ""; document.cookie = name + "=" + value + expires + "; path=/"; } function readCookie(name) { var nameEQ = name + "="; var ca = document.cookie.split(';'); for (var i = 0; i < ca.length; i++) { var c = ca[i]; while (c.charAt(0) == ' ') c = c.substring(1, c.length); if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length); } return null; } function eraseCookie(name) { createCookie(name, "", -1); } /* * END COOKIE FUNCTIONS Hello there, Could someone tell me how a javascript can get a cookie and use it as a parameter like www.mysite.com?search=COOKIEDATA Thanks you (a) 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> Hello all! I wanted to say hey as this is my first post! I will probably stick around for a little, but I need help first. I'm trying to make a code for something on a forum. It will prompt the user for a yes or cancel, then save a cookie with their answer. Then the next time the script is called, it will check for the cookie. If there is one saved, it won't prompt and use that value. Here's my breakdown (hope this is right) 1. Have a popup box that prompt for a 'yes' or 'cancel' Code: if(window.confirm("Use WHATEVER theme?")) { * * location.href = "URL HERE"; } Got that! 2. Save a cookie with the answer Here is where I need the help. I really don't have a clue other than the fact that you use setCookie(name, value, expire). I'm guessing that there will need to be something special in the value section. 3. When the script is loaded, it will check for the cookie saved and do whatever was saved Again, I need help. I know I'll need the getCookie function, but I dont know what else. As you can see, I'm rather hazy in the cookies department. If you ha any trouble and now understand it, please direct me to where you learned it as I am willing and wanting to learn this inportant function of JavaScript! I tried to provide as much detail as possible, but if you have questions ask! Any help would be greatly appreciated, whether or not it's the code I need. Whether it is direction or step by step help, I will still value it! Thanks! Hello I have below script i need add cookie to it . disable script untill cookie is not expired can you please help me <script language=javascript type="text/javascript"> <!-- Hide script from old browsers //new window script function jshow() {window.open("http://www.google.com","blank")} // End hiding script from old browsers --> </script> |