Passing data into the HTML5 History popstate Event
We owe you a short conversation about passing information through our pushstate method. We can pass information into it and this information would then come back to us once we get a popstate event call.
Video Transcript
00:00So I owe you a short conversation as I promised you earlier about the state and how do you
00:04pass information when the user clicks on that back button.
00:08So let me show you how to do it, it is quite easy.
00:11So find that push state where we created in our source code it's at line 29 and our first
00:17property which was the data, let's put an object inside of it.
00:20Let's put this an object and let's call this maybe page and our info more things.
00:28Now literally I'm just sending an object inside of it that has the information info more things,
00:33I'm going to save it.
00:35Now the next thing that I want to do is I want to go up into my events itself where we're
00:39getting that pop state and I'm just going to trace it out console.log and we'll log out
00:44that state and how do we get that data by typing e.state.
00:49Now if we do have any information it will give us the information, if not it will return
00:53null.
00:54Alright so let's see it in action, we'll go back into our browser, we'll click on
00:57refresh and again we'll go into page and then we'll click on the back button.
01:03Once we click on the back button you'll see that we're going to get our info object with
01:07the information that's inside of our application.
01:09Because I already did an experiment it's kind of like a cached saved variation, let me just
01:13click on refresh here also and then we're going to click on the back button and here
01:17you go you'll see more things with the information that we just entered inside of
01:21our object.
01:22And literally that's all you really need to know about how you pass information back
01:25and forth so if you have a scenario where you need to send information when the user
01:29clicks on the back or forth button or so on and so forth that is the way you would send
01:34that information.
