简体   繁体   中英

Detect back button in browser when the user go back to original page

I have a page that hides the query string parameter on load by using the pushState method in javascript. For example this is the original url,

www.iprocess.com?acsn=23423432423432434; 

what it does is it hides the acsn parameter on load. so it looks like this

 www.iprocess.com

problem is when I click a link inside that page and then goes back to that page it only read www.iprocess.com without the query string parameter so the data does not load.

What I want is if the user go back to that page it loads the query String parameters at the same time hides it.

This the code:

 window.history.pushState('currentpage', 'Title', window.location.pathname);

Instead of using pushState , use replaceState , this way it won't keep the parameter state in history.

Note really easy to make a live example, but here is a plnkr .
Please open the windowed mode ( “在单独的窗口中启动预览”图标 in the top right corner)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM