you can save the product information in sessionStorage or localStorage, and then delete it from the shopping cart page
- simply pass a few parameters and put them in the url;
- complex ones can be stored locally using localstorage, then obtained on other pages and parsed on the line.
//
<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');
- spell the parameters after url and get
from query.
- is stored in local storage, and sessionStorage, is used for short-term storage. LocalStorage is used for long-term storage
.
- 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 - URL parameter is passed. The previous page writes all the variables in the URL parameter, and then takes them in the latter page.
- use localStorage, sessionStorage, cookie, to store, remove and destroy
- if you have the same domain, you can use sessionStorage/localStorage, etc.
- if the domain is different, you can append parameters to url before the page jumps
- 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 ()