0

I am trying to make a Homebutton on my html page but I cannot get it to work.

This home button should always load the home page, but it should load it from the cache.
The reason for that is there a number of checkboxes on the home page and when I do window.location = "myhomepage" the page is reloaded in stead of loaded from cache, and all the checked checkboxes are empty again as are other input values.

I found that window.history.back() does not always works well when the user opened other pages before hitting the back button.
So I tried with window.history.go("myhomepage") but that does nothing at all. The page remains the same.

I have read the docs at https://www.w3schools.com/jsref/met_his_go.asp but it does not seem to work. My homepage is currently "http://localhost/test/index.php" so it tried it with this

windows.history.go("http://localhost/test/index.php")

but it does nothing at all.
I also tried variations like
.go("localhost/test/index.php")
.go("localhost/test")
but they all seem to do absolutly nothing at all.

Is there a special trick to get the window.history.go("url") working ?
Or is there a better way to do this ?

GuidoG
  • 11,359
  • 6
  • 44
  • 79
  • better way would be to use anchor element instead of js solution – Sudhir Bastakoti Feb 19 '18 at 11:07
  • As far as I'm aware `history.go()` only accepts an `int` data type, so passing it a `string` data type will **never** work, I'm assuming it has a built in feature to check the data type of the given parameter using the`typeof`operator. – JO3-W3B-D3V Feb 19 '18 at 11:13
  • @JO3-W3B-D3V According the docs in the link of my question it does – GuidoG Feb 19 '18 at 11:36
  • @GuidoG I've read up that it does, but it's partially supported, it doesn't work in all browsers. FYI W3Schools is not the best source of information, I suggest it for learning the bare bones, but for learning things like design patterns, etc. I suggest you look elsewhere, I know I'm bias to mdn, here's a link to their [docs](https://developer.mozilla.org/en-US/docs/Web/API/History) – JO3-W3B-D3V Feb 19 '18 at 11:39
  • @SudhirBastakoti I tried using an anchor but that does exact what I do not want, as described in my quesion. It reloads the page not fetches from the cache – GuidoG Feb 19 '18 at 12:12
  • @GuidoG I may have a solution... Bear with me... I'll write it out in an answer, although it may take a sec to do.... – JO3-W3B-D3V Feb 19 '18 at 12:49

0 Answers0