pushState and popstate

Поделиться
HTML-код
  • Опубликовано: 11 дек 2024

Комментарии • 67

  • @artemnakhodkin9548
    @artemnakhodkin9548 7 лет назад +10

    Cool! Pretty well explained!
    But it would be worth to mention, that history object also has a property "state", that handles current state. For example, if your page loaded initially, there would be no "popstate" event fired.
    To make the conjunction between application state and history API state, you'll have to read history.state property to make a proper initialization.

    • @GeekLaunch
      @GeekLaunch  7 лет назад +1

      Hey, thanks for the extra insight, it's really appreciated.

  • @tabgimbarr
    @tabgimbarr 3 года назад +1

    Dynamic changing title is actualy supported by any browsers, it just needs right way to code it. The code is document.title = 'test'

  • @nafaa-news
    @nafaa-news 4 года назад

    You know what made me happier in this video? it's your last comment, "I had a heck of a time learning this API". So, I'm not the only one got trouble with this API.
    Thank you for this clear explanation.

  • @pedrocarlosdeoliveiradossa656
    @pedrocarlosdeoliveiradossa656 Год назад +1

    11:28 Thanks for your time, excelent tutorial.

  • @glyakk
    @glyakk 3 года назад

    Still a great tutorial, also the sassy argument you had with yourself 6:40 was amusing ;)

  • @xsomili5501
    @xsomili5501 4 года назад

    as a new learner who is bad at javascript, i find this easy to follow:) thankyou

  • @ruzzlgreen3436
    @ruzzlgreen3436 3 года назад +1

    I love how soothing your voice is

  • @soy-dave
    @soy-dave 5 лет назад +4

    Great explanation! Didn't know this API existed in HTML5.

  • @biancotore
    @biancotore 4 месяца назад

    Thanks, very good tutorial!

  • @namng5422
    @namng5422 3 года назад +1

    Best tutorial , please more webAPIs !!!

  • @kayoscreed
    @kayoscreed 6 лет назад

    It's great, I can use it for sure. Also very helpfull with stateless webapps to store all Parameters in and reload.

    • @GeekLaunch
      @GeekLaunch  6 лет назад

      +Kayoscreed Thanks for watching!

  • @cr4zyd4n666
    @cr4zyd4n666 6 лет назад +1

    Hey this video was extremely helpful it took me ages to get it but ive downloaded the code and played around with it and now i get it! I think i've solved the problem on my site now thank you

    • @GeekLaunch
      @GeekLaunch  6 лет назад +1

      That's awesome, glad to hear you figured it out!

  • @CodeWithMukeshBadgujar
    @CodeWithMukeshBadgujar 4 года назад +1

    One Problem in your code, i download from your git and run it, now see, when i click any of div and if i refresh the page, then url not works, gives Error : The requested URL /pushstate-and-popstate-master/selected=box-2 was not found on this server.
    Plzz tell me how to solve it...

    • @KnightAlmighty
      @KnightAlmighty 4 года назад +1

      Because you should use urls of existing pages. Watch a piece after 6:10

  • @RaldinCasidar
    @RaldinCasidar 4 года назад

    I know a library that will let all major browser support the entire history api .
    Its called history.js on github . check it !

  • @conceptclearcode
    @conceptclearcode 29 дней назад

    I have a woocommerce checkout page and when i'm doing click on go back button i'm getting confirm form resubmission message on a page how to remove this message and show form

  • @ronaldc8634
    @ronaldc8634 5 лет назад

    The code in the video it will break on refresh because the browser will request a nonexistent page.
    How do I make it an existing page?

  • @qzbnyv
    @qzbnyv 4 года назад +1

    Your voice reminds me of Jon Lovett's (I listen to too many podcasts). Also great video, very helpful example to learn this API's basics. Thanks!

    • @qzbnyv
      @qzbnyv 2 года назад +1

      So I’m back here watching this video again several years later.
      Have essentially only been using hashchange since back then, but figured it’s time to properly understand popstate/pushState and implement it in PureScript.
      (I’m listening to basically zero podcasts these days, and definitely no political stuff anymore, but am addicted to silly LitRPG audiobooks instead)
      (If I’m back here in another few years watching the video again, I probably won’t comment as it’d give away a lack of progress 😅)

  • @omshiv3179
    @omshiv3179 Год назад

    Thankx for your good explanation sir! It was really helpful for me.

  • @drusttaib607
    @drusttaib607 5 лет назад

    hey man thanks for the video, I have some questions regarding ajax. 1- if you check youtube, they are using ajax to load parts of the html, but what is surprising is, you can also navigate different parts with url link, (i mean, if they change some parts of the html, it means they have only one web page) . How to change different parts of the html and make it accessible with link also? 2- the forward and backward event you mentioned. how can we save an entire div with the elements inside it, and how can we save the entire html page?
    please tell me if you didn't get any of these

    • @GeekLaunch
      @GeekLaunch  5 лет назад

      For your first question, the answer would be that the changes RUclips performs on the client side when navigation occurs result in the same (or close enough to the same) UI as the server would generate were you to access the new URL directly. Not sure I completely understand the second question.

    • @drusttaib607
      @drusttaib607 5 лет назад

      @@GeekLaunch i have a
      And the only thing that I change with ajax is the elements inside that div. How can I create pushstate for backward and forward with my situation?

  • @Matthew-cp1zh
    @Matthew-cp1zh 4 года назад +1

    *When he hovered over those boxes.*
    *Anyone else hear "ee er ee er"*

  • @sauldownbadman876
    @sauldownbadman876 Год назад

    What does the e => do? I'm really confused by it

    • @kyriekwsta770
      @kyriekwsta770 26 дней назад

      it's an arrow function. basically the event listener takes an event ("click") and a callback function. the e as a parameter to the callback function in the event listener, represents the event object and its properties.

  • @mohanmongia3704
    @mohanmongia3704 3 года назад

    Just a question. When we use history.pushState() , doesn't it pushes to a stack rather than an array as mentioned by you?

    • @aiamfree
      @aiamfree Год назад

      I think you're correct because in popstate you just call it as e.state without indexing...

  • @Couchwurst
    @Couchwurst 4 года назад

    Nice! A concise and really well rounded video! Thank you.

  • @jesusonherra7596
    @jesusonherra7596 2 года назад

    why do you use if else to pass null value? why not just using selectBox(e.state?.id); ? It would eventually pass null where needed

    • @Maxim9575
      @Maxim9575 Год назад

      VIdeo captured 5 yrs ago, there wasn't optional chain.

  • @Shuvooa
    @Shuvooa 4 года назад

    Very good explanation

  • @omar99ize
    @omar99ize 6 лет назад

    what happens in case someone hit the reload button? Thanks for the video!

    • @GeekLaunch
      @GeekLaunch  6 лет назад +1

      Sorry I missed your comment! The API will still work as intended, but the way I wrote the code in the video it will break because then the browser will request a nonexistent page. What I should have done is make a box click change a query parameter instead of the actual path of the URL. :/

  • @codewithmePuneet
    @codewithmePuneet 6 лет назад

    which text editing software you are using?

    • @GeekLaunch
      @GeekLaunch  6 лет назад

      Sorry I missed your comment - I'm using Visual Studio Code in this video.

  • @adhoccerswings
    @adhoccerswings 7 месяцев назад

    Awesome! Btw: I tried this as files (=clicking on the index.html in my folder), and that didn't work -> had to do local hosting (used Five Server). When I didn't do local hosting, my browser lit up like a Christmas tree and yelled at me quite meanly:
    "
    Security Error: Content at file://[my_folder_location_here]selected=box-2.
    Uncaught DOMException: The operation is insecure.
    "
    so that ^^ was when I tried WITHOUT local hosting.
    Side note: I think you can write shorter:
    "let boxes = document.querySelectorAll(".box")"
    This selects all the elements with class "box".

  • @suhaib404
    @suhaib404 6 лет назад

    That was on point! Exactly what I was looking for. Subscribed!!

    • @GeekLaunch
      @GeekLaunch  6 лет назад +1

      Thanks for subscribing! I'm currently on an extended break (school + work) but I'll be sure to produce more content in the future!

  • @AlphaTech-y3y
    @AlphaTech-y3y Месяц назад

    Thank you this is the thing i need now

  • @play.7242
    @play.7242 Год назад

    Its like you sade youseless. But the basic is require for individual project

  • @wadiemh
    @wadiemh 3 года назад

    Thanks dude, that was super helpful

  • @sobirmalilov8838
    @sobirmalilov8838 3 года назад

    Thanks bro your tutorial is useful for me

  • @vishal_taywade
    @vishal_taywade 2 года назад

    Nice video 👌 appreciate your efforts 👍

  • @GuitaristZep
    @GuitaristZep 2 года назад

    how to know if user goes forward or back using popstate?

  • @Vietnamcamping89
    @Vietnamcamping89 6 лет назад

    why this can't running on my project (On server ) :(

    • @GeekLaunch
      @GeekLaunch  6 лет назад

      I don't know, sorry! Hopefully you get it fixed!

  • @tonl6361
    @tonl6361 4 года назад

    That code doesn`t work in old IE version.

    • @GeekLaunch
      @GeekLaunch  4 года назад +2

      Stop using old versions of IE!!

  • @JohnmarkAlvarado-ic4vf
    @JohnmarkAlvarado-ic4vf 2 месяца назад

    Big Thanks bros

  • @Shaambhavee9
    @Shaambhavee9 6 лет назад

    Thanks for sharing this!

  • @wirandhikablogs
    @wirandhikablogs 7 лет назад +2

    greats, Thanks aLot man!

    • @GeekLaunch
      @GeekLaunch  7 лет назад

      +Wira Andhika You're welcome, glad you liked it!

  • @trfaruk44
    @trfaruk44 5 лет назад +1

    Thank you :)

  • @aiamfree
    @aiamfree Год назад

    Building a state tool for a SPA-webapp.. not fun lol...!

  • @LonIlesanmi
    @LonIlesanmi 7 лет назад

    This is cool man

    • @GeekLaunch
      @GeekLaunch  7 лет назад

      Thanks, I'm glad you think so!

  • @ukwerna
    @ukwerna 6 лет назад

    Cheers!

  • @chickendev5759
    @chickendev5759 4 года назад

    thank you so muchhhhhhhhh

  • @kobenade
    @kobenade 4 года назад

    'Completely pointless' technology that is the basis of single-paged applications :)