简体   繁体   中英

How to keep html file state the same when changing through files

I made 2 html files, one is mainly using javascript ,(the index). And another that is for the info . So in the index.html file when opened it displays a main menu and a button called books and when clicked on it displays a list of book titles and etc. and when chosen one of them it will send you to the 2nd html file , the info.html file. I made a button on the info.html file where it will send you back to the index.html file, but when i click on it goes back to the main menu screen and not the books list screen.

Is there anyway to have the current state of the previous html file stay the same?

(I made the mainmenu dissapear and books tab reappear using javascript.)

When user navigated from Page 2 (info.html) to Page 1 (index.html) using back button, you need some identifier to trigger same functionality which you are triggering on Books button click to displays a list of book titles and etc.

So technically, you need to add a query string identifier on link of Back button

ie <a href="/index.html?back=1"> Back </a>

Now, read value of query string identifier in javascript of index.html and conditionally trigger the same functionality which your are triggering when user click on Books button.

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