Welkom bij Joomla!NL

Om alle mogelijkheden van dit forum te kunnen gebruiken, moet je je eerst registreren.

Cookie path problem

Cookie path problem

20 jul 2017 16:00 - 20 jul 2017 16:36
#1
i try to make a funtion i really need my own script becose i will add more later.
if i create a cookie sampe : BIGFONT = on.
my font will stay big even if i go to a otter page. (cookie)
but if its a subpage its make a new cookie for that path.

its simple on or off for all page inclu. subpages

sameone know how i can juse the same cookie even if its a subpath. like google.com/subpath/
i will add a screenshot thats make my problem clear.

tnx
Code:
jQuery(document).ready(function(){ /* toggle fontsize */ var FontSizeOptie = docCookies.getItem("FontSize"); if (FontSizeOptie == "aan") { jQuery('#page').addClass('fontsizebig'); jQuery('.togglefontsize').addClass('active'); } jQuery('.togglefontsize').click(function(){ if (jQuery("#page" ).hasClass("fontsizebig") ) { jQuery('#page').removeClass('fontsizebig'); jQuery('.togglefontsize').removeClass('active'); docCookies.setItem("FontSize", "uit"); } else { jQuery('#page').addClass('fontsizebig'); jQuery('.togglefontsize').addClass('active'); docCookies.setItem("FontSize", "aan"); } }); });

Code:
jQuery(document).ready(function(){ docCookies = { getItem: function (sKey) { if (!sKey || !this.hasItem(sKey)) { return null; } return unescape(document.cookie.replace(new RegExp("(?:^|.*;\\s*)" + escape(sKey).replace(/[\-\.\+\*]/g, "\\$&") + "\\s*\\=\\s*((?:[^;](?!;))*[^;]?).*"), "$1")); }, /** * docCookies.setItem(sKey, sValue, vEnd, sPath, sDomain, bSecure) * * @argument sKey (String): the name of the cookie; * @argument sValue (String): the value of the cookie; * @optional argument vEnd (Number, String, Date Object or null): the max-age in seconds (e.g., 31536e3 for a year) or the * expires date in GMTString format or in Date Object format; if not specified it will expire at the end of session; * @optional argument sPath (String or null): e.g., "/", "/mydir"; if not specified, defaults to the current path of the current document location; * @optional argument sDomain (String or null): e.g., "example.com", ".example.com" (includes all subdomains) or "subdomain.example.com"; if not * specified, defaults to the host portion of the current document location; * @optional argument bSecure (Boolean or null): cookie will be transmitted only over secure protocol as https; * @return undefined; **/ setItem: function (sKey, sValue, vEnd, sPath, sDomain, bSecure) { if (!sKey || /^(?:expires|max\-age|path|domain|secure)$/.test(sKey)) { return; } var sExpires = ""; if (vEnd) { switch (typeof vEnd) { case "number": sExpires = "; max-age=" + vEnd; break; case "string": sExpires = "; expires=" + vEnd; break; case "object": if (vEnd.hasOwnProperty("toGMTString")) { sExpires = "; expires=" + vEnd.toGMTString(); } break; } } document.cookie = escape(sKey) + "=" + escape(sValue) + sExpires + (sDomain ? "; domain=" + sDomain : "") + (sPath ? "; path=" + sPath : "") + (bSecure ? "; secure" : ""); }, removeItem: function (sKey) { if (!sKey || !this.hasItem(sKey)) { return; } var oExpDate = new Date(); oExpDate.setDate(oExpDate.getDate() - 1); document.cookie = escape(sKey) + "=; expires=" + oExpDate.toGMTString() + "; path=/"; }, hasItem: function (sKey) { return (new RegExp("(?:^|;\\s*)" + escape(sKey).replace(/[\-\.\+\*]/g, "\\$&") + "\\s*\\=")).test(document.cookie); } }; // docCookies.setItem("test1", "Hello world!"); // docCookies.setItem("test2", "Hello world!", new Date(2020, 5, 12)); // docCookies.setItem("test3", "Hello world!", new Date(2027, 2, 3), "/blog"); // docCookies.setItem("test4", "Hello world!", "Sun, 06 Nov 2022 21:43:15 GMT"); // docCookies.setItem("test5", "Hello world!", "Tue, 06 Dec 2022 13:11:07 GMT", "/home"); // docCookies.setItem("test6", "Hello world!", 150); // docCookies.setItem("test7", "Hello world!", 245, "/content"); // docCookies.setItem("test8", "Hello world!", null, null, "example.com"); // docCookies.setItem("test9", "Hello world!", null, null, null, true); // alert(docCookies.getItem("test1")); //document.cookie = "name=oeschger"; //document.cookie = "favorite_food=tripe"; //alert(document.cookie); //displays: name=oeschger;favorite_food=tripe });

:sick:

Dit bericht bevat een afbeelding als bijlage.
Log in of registreer om die te bekijken

Laatst bewerkt 20 jul 2017 16:36 door Jelle.
  • janjoris
  • janjoris's berichtenfoto Heeft onderwerp gestart
  • Nieuw op Joomla!NL
  • Nieuw op Joomla!NL
  • Berichten: 3

Cookie path problem

20 jul 2017 16:25
#2
Hallo janjoris,

Namens het Joomla!NL team heet ik je van harte welkom op dit forum.

Dit is een Nederlandstalig forum. Vriendelijk verzoek om je vraag in het Nederlands te stellen. Als je per se in het Engels wilt communiceren dan kan je terecht op forum.joomla.org/
Groetjes, Astrid
Gebruik de zoekfunctie van dit forum voordat je een nieuwe vraag plaatst.
Vragen uitsluitend via dit forum.
yndi.nl - kvk 17157725
Is je vraag beantwoord? Dan kan je het draadje zelf sluiten .
Wil je Joomla!NL steunen? Dat kan met een donatie.

  • Astrid
  • Astrid's Profielfoto
  • Moderator + Technisch team
  • Moderator + Technisch team
  • Berichten: 37094
Moderators: Juliank92JellePeterRomke
Tijd voor maken pagina: 1.125 seconden

Wil je Joomla!NL steunen?

Steun Joomla!NLAlle teamleden werken enthousiast, op vrijwillige basis, mee aan Joomla!NL. Maar een website met forum kost nu eenmaal geld. Dus als je Joomla!NL wilt steunen, dan kan dat, graag zelfs!

Lees hier meer informatie