Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to link a webpage to itself without first knowing its name?

To link a page to itself (e.g. http://example.com/folder/ThisPage.html), we can simply create a href as such:

ThisPage.html:

<a href="ThisPage.html">Link</a>

This works, but has the disadvantage of needing to be updated when the file name changes. For example, if the file name changes to ThatPage.html, our href needs to change accordingly to <a href="ThatPage.html">Link</a>.

I'm looking for an alternative without that disadvantage. I've tried:

  • <a href="?">Link</a>

    Doesn't work as <a href="ThisPage.html">Link</a> does, because it appends a "blank query part" (question mark) to the URL.

  • <a href="">Link</a>

    Doesn't work as <a href="ThisPage.html">Link</a> does, on some browsers (e.g. Opera).

How do we link a page to itself, without having to update the relevant portion when the name of the page changes?

Note: JavaScript not allowed.

like image 912
Pacerier Avatar asked Mar 15 '13 17:03

Pacerier


2 Answers

Just use <a href="?">Link</a>. Nobody cares about the question mark appended to the URL. It does the requirement and that is what counts right?

like image 156
Bart Avatar answered Sep 28 '22 00:09

Bart


If you want it to go nowhere, you can use

<a href="javascript:;">link</a>

But if you want it to reload the page, you'll have to go with JavaScript.

If you want to reload the page you could use the Meta refresh tag

http://www.w3.org/TR/WCAG20-TECHS/H76.html

like image 45
Will Avatar answered Sep 28 '22 01:09

Will