How do I transfer received data between two html pages?

when I do a shopping page (). Request to jump from an item details page to the shopping cart page (product name, price data is required). How does the shopping cart page receive information from the merchandise page? My current tools only use html and js,. Can I use them to implement them?

Aug.13,2021

you can save the product information in sessionStorage or localStorage, and then delete it from the shopping cart page


  1. simply pass a few parameters and put them in the url;
  2. complex ones can be stored locally using localstorage, then obtained on other pages and parsed on the line.

  • url pass value
// 
<a id='a'></a>
<script>
    var a = document.getElementById('a');
    a.setAttribute('href', 'b.html?name='+name);
</script>
// 
window.location.search
  • localStorage local storage
// 
localStorage.setItem('name', name);
// 
localStorage.getItem('name');

  1. spell the parameters after url and get
  2. from query.
  3. is stored in local storage, and sessionStorage, is used for short-term storage. LocalStorage is used for long-term storage
  4. .
  5. stored in cookie

1Based session Storage or localStorage stores commodity information

2, take the merchandise ID to URL, then intercept the ID from URL and request the merchandise information again


Jump from an item details page to the shopping cart page, you should first add the item to the shopping cart, and then jump to it; instead of jumping directly to the past!

even if you want to jump directly, there are two ways for a pure front end:

    The
  1. URL parameter is passed. The previous page writes all the variables in the URL parameter, and then takes them in the latter page.
  2. use localStorage, sessionStorage, cookie, to store, remove and destroy

  1. if you have the same domain, you can use sessionStorage/localStorage, etc.
  2. if the domain is different, you can append parameters to url before the page jumps
  3. in order to avoid trouble, it is best to transfer through the background.

1, put parameters after url, parse
2 after jumping, local storage localStorage


define an object first

var _goodsInfo = {}

set a function to store

function setGoodsInfo (obj){
    _goodsInfo = obj
}

set a function to get

function getGoodsInfo (){
    renturn _goodsInfo
}

send data to

when clicking on an item
setGoodsInfo()

then get

on another page
getGoodsInfo ()
Menu