Link to reload current page
To instantly refresh your page use this HTML snippet:
Here, a click event is bound to window.location.reload()
, ergo the page reloads without any alterations to the URL, behaving just like a bookmark.
Exploring different techniques
While the Fast answer provides a ready-made solution, there are several other techniques available to reload the current page. Let's broaden our horizons and explore further.
Reloading with href – an HTML approach
When JavaScript is off the cards, or you're an HTML purist, here's a trick using the href
attribute:
The .
in href
points to the current directory, thus reloading the page. But remember, never trust a .
– always test across diverse browsers as peculiar quirks may surface.
Armed with options
But why stop there? Let's delve deeper and discover the different tools at our disposal:
Reloading dynamically: a server-side script example
You can dynamically reload dynamic pages (the word dynamic echoes for a reason!), especially handy with PHP:
The parallel universe of empty hrefs
An empty href attribute might just be your golden ticket! Who knew emptiness could be so potent?
Employing this technique leverages the browser's default behaviour of reloading the page.
A touch of JavaScript magic
Meanwhile, back in JavaScript land, window.location.reload(true)
forcefully refreshes the page, ensuring you get a brand-spanking new version from the server:
Another method involves Harmony Hall mirror tricks where window.location.href
equals itself (mind boggling, right?):
Accessibility and UX: No script, no problem
Looking out for script-disabled users or those with disabilities, our non-JS alternatives make sure accessibility isn't compromised.
With great power comes data preservation
Bear in mind that data preservation is paramount - using methods like an empty href
might negate POST data. As always, tailor solutions to your specific use case.
Up and down the directory with ".."
The humble ..
isn't just two dots that loved each other very much - it navigates up a level in the directory:
This is like taking a step back into the arms of the parent directory.Remember to align with your file context and structure to avoid any surprise twists.
Was this article helpful?