What exactly is the pushState state object in HTML?

JavascriptWeb DevelopmentFront End Scripts

Use the pushSate object to update the page when the user navigates back through history. Let us see an example to include the selected color that creates a history entry −

function display(color) {
   var myState = { selectedColor: color },
   myTitle = "Page title",
   myPath = "/" + color;
   history.pushState(myState, myTitle, myPath );
};

Now we will use the popstate event to update the selected color −

$(window).on('popstate', function(event) {
   var myState = event.originalEvent.state;
   if (statemyState {
      selectColor( myState.selectedColor );
   }
});
raja
Published on 05-Apr-2018 12:53:57
Advertisements