2

I have tried to google my way through this, and haven't found the answer I am looking for. What I have found is how to reference your own location: here and how to reload your current page: here. What I am looking for is a bit more in depth.

I have a small website that is indexed into JSON. On my homepage I have a textbox and a button. When an user presses the button my Java Script registers the event and sends the contents of the textbox to a PHP file on the server. The PHP cross-references my JSON index for the search contents. If anything contains my search contents, the PHP throws together a HTML element with a preview of the indexed element along with a link to the content and returns the html to my JS. My JS simply appends the html element to the webpage and the user sees the results (with help of css rules).

When the search results contains an element on the current page I run into an issue: clicking the link will focus the page on the content, but it won't remove the results element. What I would like to happen is for the page to re-load when I click the link. That way the HTML element with the search results would no longer appear/exist. Is there a HTML attribute that sets a link to re-load the webpage on click?

I know I could come up with a JS/JQuery solution to this. But I'd like to use a simple approach if it exists.

Thanks!

Community
  • 1
  • 1
Matt
  • 41
  • 7

1 Answers1

2

I want to thank @yuriy636 for the quick response. Sometimes the simple things go right past you. Here is the simple solution.

<a href="goSomewhere" onclick="location.reload();">link</a>

Just a note for those looking to use this solution: a location.reload() is not going to give you a true refresh, but rather it will reload from the cache. You can force it to reload from the server by setting the forceGet parameter to true: location.reload(true). W3Schools

Matt
  • 41
  • 7