Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

javascript window.onpopstate example

window.onpopstate = function(event) {
  alert("location: " + document.location + ", state: " + JSON.stringify(event.state));
  const urlParams = new URLSearchParams(window.location.search);
  const myParam = urlParams.get('myParam');
  //update model accordingly
};

history.pushState({page: 1}, "title 1", "?page=1");
history.pushState({page: 2}, "title 2", "?page=2");
history.replaceState({page: 3}, "title 3", "?page=3");
history.back(); // alerts "location: http://example.com/example.html?page=1, state: {"page":1}"
history.back(); // alerts "location: http://example.com/example.html, state: null
history.go(2);  // alerts "location: http://example.com/example.html?page=3, state: {"page":3}
Comment

PREVIOUS NEXT
Code Example
Javascript :: Nestjs download 
Javascript :: const is available in es6 
Javascript :: javascript new date invalid date dd/mm/yyyy 
Javascript :: webpack build watch 
Javascript :: reactjs cdn file 
Javascript :: js change number to string 
Javascript :: outer click on div hide div in jqeury 
Javascript :: javascript how to do else if 
Javascript :: chart.js clear data 
Javascript :: Uncaught SyntaxError: Cannot use import statement outside a module 
Javascript :: define an async function 
Javascript :: dayjs after 
Javascript :: javascript moment 
Javascript :: Escaping double quotation in javascript 
Javascript :: moment to date object 
Javascript :: change image onclick js 
Javascript :: node.js check if a remote URL exists 
Javascript :: how to add options to select in jquery array 
Javascript :: postgres boolean column 
Javascript :: JavaScript find the shortest word in a string 
Javascript :: form-data upload file 
Javascript :: js check collision 
Javascript :: import in react js 
Javascript :: js set iframe code 
Javascript :: usb react native device not found 
Javascript :: Find Smallest Number by function in Javascript 
Javascript :: new line with javascript write 
Javascript :: react js bootstrap select option required 
Javascript :: add countdown timer to javascript quiz 
Javascript :: mongoose query using an arry 
ADD CONTENT
Topic
Content
Source link
Name
3+7 =