Home > front end >  Questions about the cookies, how to jump every time a link to save an address, then taken out
Questions about the cookies, how to jump every time a link to save an address, then taken out

Time:09-29

Is probably so, after entering a page, store the current page URL addresses to cookies, and then click the link from the page after the jump, the original storage, to store the new current page URL links, and so on, as long as have been from the original pages in each page and then click on the links to jump by the jump page at the URL will be stored in the COOKIE,
After I again how to withdraw the current page from the COOKIE jumps over previous page link?

Click physical keys on his mobile phone because I want to be returned by the function, and add a meta page source to stop the record of the page, so the document. The referrer unable to get back to record, so think of use cookies to make, but when to begin to get found too difficult, I don't know how to start, also searched a lot of information, without access to relevant information, so have to come to consult, still hope BBS bosses can give help ah, thank you very much,

Below is that mobile phones bring back the JS code,

 
PushHistory ();
Window. The addEventListener (" popstate ", function (e) {
If (document. The referrer==' ') {
Window. The location="without the referrer will jump to specify page address";
} else {
Window. The history. The go (1);
}
}, false);

The function pushHistory () {
Var state={
Title: "title",
Url: "#"
};
Window. The history. PushState (state, "title", "#");
}

CodePudding user response:

 
Use cookie is bad, should use the sessionStorage
<script type="text/javascript">
Var historyArr=JSON. Parse (sessionStorage. HistoryArr | | "[]");
The console. The log (historyArr);
If (historyArr [0]!=location. Href) {
HistoryArr. Unshift (location. Href);
SessionStorage. HistoryArr=JSON. Stringify (historyArr);
}
The function historyBack () {
If (historyArr. Length<2) return;
HistoryArr. Shift ();
SessionStorage. HistoryArr=JSON. Stringify (historyArr);
The location. The href=https://bbs.csdn.net/topics/historyArr [0];

}
</script>

CodePudding user response:

reference 1/f, the sky wave response:
 
Use cookie is bad, should use the sessionStorage
<script type="text/javascript">
Var historyArr=JSON. Parse (sessionStorage. HistoryArr | | "[]");
The console. The log (historyArr);
If (historyArr [0]!=location. Href) {
HistoryArr. Unshift (location. Href);
SessionStorage. HistoryArr=JSON. Stringify (historyArr);
}
The function historyBack () {
If (historyArr. Length<2) return;
HistoryArr. Shift ();
SessionStorage. HistoryArr=JSON. Stringify (historyArr);
The location. The href=https://bbs.csdn.net/topics/historyArr [0];

}
</script>



Completely do not understand sessionStorage, how do I perform in my game code? Because my physical keys on each point of a mobile phone, no matter how many times jump page, from which the jump page at the next higher level, will return the current page, press the return key at the next higher level has been page until the return to the original in the page, then point returns, returns the specified page links, just said are going to make me dizzy,,,
  • Related