Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Link to reload current page

Tags:

html

hyperlink

Is it possible to have a normal link pointing to the current location?

I have currently found 2 solutions, but one of them includes JavaScript and in the other you have to know the absolute path to the page:

<a href="#" onclick="window.location.reload(true);">1</a> <a href="/foobar/">2</a> <a href="#">3 (of course not working)</a> 

Is there any way of doing this, without using JavaScript or knowing the absolute path?

like image 727
Tyilo Avatar asked Nov 17 '11 21:11

Tyilo


People also ask

How do you refresh the current page in HTML?

Most people know it can be done by hand by holding the shift key and clicking the “Refresh” (on IE) or “Reload” (on Navigator) buttons.

How do I refresh a page using anchor tag?

After you set the specified URL into location, issue window. location. reload(true) . This will force browser to reload the page.

Does window location href reload the page?

href="location_URL" ,then browser cache data for 600 seconds, which means 10 minutes. On the other hand, if you use window. location. reload(true) , then the browser will skip the cache and ,then, reload page from server.


1 Answers

I have been using:

<a href=".">link</a> 

Have yet to find a case and/or browser where it does not work as intended.

Period means the current path. You can also use .. to refer to the folder above the current path, for instance, if you have this file structure:

page1.html folder1     page2.html 

You can then in page2.html write:

<a href="../page1.html">link to page 1</a> 

EDIT:

I'm not sure if the behaviour has changed or if it was always like this, but Chrome (and maybe others) will treat periods as described above as regarding directories, not files. This means that if you are at http://example.com/foo/bar.html you are really in the directory /foo/ and a href value of . in bar.html will refer to /foo/ rather than bar.html

Think of it as navigating the file system in a terminal; you can never cd into a file :)

EDIT 2:

It seems like the behaviour of using href="." is not as predictable anymore, both Firefox and Chrome might have changed how they handle these. I wouldn't rely entirely on my original answer, but rather try both the empty string and the period in different browsers for your specific use and make sure you get the desired behaviour.

like image 118
Markus Amalthea Magnuson Avatar answered Sep 19 '22 11:09

Markus Amalthea Magnuson