Learn how JavaScript COOKIES work! 🍪

2022 ж. 22 Сәу.
41 383 Рет қаралды

#JavaScript #cookies #tutorial
// cookie = a small text file stored on your computer
// used to remember information about the user
// saved in name=value pairs
//console.log(navigator.cookieEnabled);
//document.cookie = "firstName=Spongebob; expires=Sun, 1 January 2030 12:00:00 UTC; path=/";
//document.cookie = "lastName=Squarepants; expires=Sun, 1 January 2030 12:00:00 UTC; path=/";
//let allCookies = document.cookie;
//console.dir(allCookies);

Пікірлер
  • const firstText = document.querySelector("#firstText"); const lastText = document.querySelector("#lastText"); const submitBtn = document.querySelector("#submitBtn"); const cookieBtn = document.querySelector("#cookieBtn"); submitBtn.addEventListener("click", () => { setCookie("firstName", firstText.value, 365); setCookie("lastName", lastText.value, 365); }); cookieBtn.addEventListener("click", () => { firstText.value = getCookie("firstName"); lastText.value = getCookie("lastName"); }); function setCookie(name, value, daysToLive){ const date = new Date(); date.setTime(date.getTime() + (daysToLive * 24 * 60 * 60 * 1000)); let expires = "expires=" + date.toUTCString(); document.cookie = `${name}=${value}; ${expires}; path=/` } function deleteCookie(name){ setCookie(name, null, null); } function getCookie(name){ const cDecoded = decodeURIComponent(document.cookie); const cArray = cDecoded.split("; "); let result = null; cArray.forEach(element => { if(element.indexOf(name) == 0){ result = element.substring(name.length + 1) } }) return result; } Document first name: last name: submit get cookies

    @BroCodez@BroCodez2 жыл бұрын
  • Thank you, great practical examples, I understood cookies 😍

    @chiculitamihaela8076@chiculitamihaela8076 Жыл бұрын
  • Was supposed to use the js-cookie library, until I saw this video and decided to write it out myself. Well explained!

    @pexeixv@pexeixv11 ай бұрын
  • Completed the JavaScript playlist.. Thanks Bro

    @ALLINONE-ko6sv@ALLINONE-ko6sv Жыл бұрын
  • Thank you so much this tutorial was very useful and I really learned what I was doing.

    @mrguy2@mrguy2 Жыл бұрын
  • Great tutorial. Thank you

    @kirillzlobin7135@kirillzlobin71359 ай бұрын
  • awesome explanation!

    @one111won@one111won Жыл бұрын
  • Finally i can store data within a client your a lifesaver

    @DlguyIsbad@DlguyIsbad5 ай бұрын
  • Thanks for the amazing video! Where is your autocomplete? 😄

    @dmytro_kruhlyi@dmytro_kruhlyi7 ай бұрын
  • Can you plz also do fortran tutorials. I need it for my exams but I can't find someone who can explain it well like you

    @RohitCantSing@RohitCantSing2 жыл бұрын
  • super underrated!!!

    @ripolas@ripolas11 ай бұрын
  • Thank you bro not disappointed as always, can you do a video about promises,callbacks,asyncs.. i am really struggling on those

    @addda1899@addda18992 жыл бұрын
    • He already did

      @ytgod2094@ytgod20949 ай бұрын
  • Thanks!

    @MrLoser-ks2xn@MrLoser-ks2xn Жыл бұрын
  • thank you so much for this valuable content bro code 🙏🙏🙏🙏🙏🙏🙏

    @adityashinde7815@adityashinde78153 ай бұрын
  • Bro thank you for your tutorials and can you please do a course in django python?.

    @Ken-zh4gu@Ken-zh4gu3 ай бұрын
  • great video

    @shegyoo@shegyoo6 ай бұрын
  • wow greate tutorial

    @coocoo3336@coocoo3336 Жыл бұрын
  • thank bro

    @Plapx3@Plapx3 Жыл бұрын
  • Very cool my bro code. But i'd want to suggest that you replace == with === in 08:27

    @TechBro4Life-uk8po@TechBro4Life-uk8poКүн бұрын
  • Thanks. If one day my startup makes enough money I'll pay you back for this.

    @mahir04@mahir04 Жыл бұрын
    • 🤣

      @doublesushi5990@doublesushi59909 ай бұрын
    • We need more people like you 👏

      @chiggywiggy524@chiggywiggy5246 ай бұрын
  • Actually, you could use the browser console and go into the application sub-menu, there, cookies, local storage and session storage are displayed in a table!

    @hunin27@hunin275 ай бұрын
  • Is there any way to copy a specified cookie to your clipboard?

    @Kattoe@Kattoe Жыл бұрын
  • sir, How to overcome document.object not defined 😔

    @mdmahmudjamil5802@mdmahmudjamil5802Ай бұрын
  • Ďakujeme za zdieľanie. Viem, že Morelogin dokáže chrániť súkromie.

    @fujiaaniya@fujiaaniya Жыл бұрын
  • That was complicated 🥵🥵🥵

    @lucabinder9829@lucabinder9829 Жыл бұрын
  • i don't understand The , if(element.indexOf(name){ result = element.substring(name.length + 1); } is there anyone who can explain to me?

    @natnaeltaye@natnaeltaye10 күн бұрын
  • when i write document.cookie = "firstName=SpongeBob"; my cookie stays blank idk why /_ \

    @zibozhao5789@zibozhao57892 жыл бұрын
  • lets go

    @TheSavageNoob@TheSavageNoob2 жыл бұрын
  • is this what consistency is?

    @rudrarajkar1116@rudrarajkar11162 жыл бұрын
    • Yup

      @Iamafuckingmadlad@Iamafuckingmadlad Жыл бұрын
  • the video title says it all hahaha

    @tayaobilly8577@tayaobilly85772 жыл бұрын
  • milk and cookies

    @crazyMando_me@crazyMando_me3 ай бұрын
  • Remove the word "Beginners" from the playList title

    @abuzarn7310@abuzarn7310 Жыл бұрын
  • first comment

    @smilekick6025@smilekick60252 жыл бұрын
  • cookies dont work, they stay blank xd

    @Vairoon@Vairoon Жыл бұрын
KZhead