Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can a plain HTML link (A) reload a page without query string values

Tags:

html

I want to essentially reload the page I'm on without some of the query strings which might be present (thus changing content on the page). I've found that leaving the href tag empty like so href="" works, but I wonder if this a safe method, ie. does it work in older browsers?

Edit:

In fact scrap that, leaving it blank doesn't work (some great testing by me there). So, I guess my question now is, how can I reload the same page without any query string values? And without knowing the file name and without using Javascript. I guess I'm looking for something like / or #.

like image 632
Chris Avatar asked Nov 24 '11 14:11

Chris


2 Answers

I think I know a trick. When you use a <form> tag with empty action and no (or GET) method parameter it will use your url but will replace the GET parameters (query string) with the values in your form, so:

On page http://example.com/foo.html?query=string

<form action="">
    <input type="submit" value="hello" />
</form>

If you click on the button you will get to:

  • http://example.com/foo.html (Firefox 8)
  • http://example.com/foo.html (Internet Explorer 9)
  • http://example.com/foo.html? (Chrome 15)
  • http://example.com/foo.html? (Safari 5)

Edit: the trailing question mark is likely a Webkit issue.

like image 185
aorcsik Avatar answered Oct 12 '22 19:10

aorcsik


There is an interesting post about empty URLs. It refers to RFC 3986, which defines URLs.

Basically, from a spec point of view you should be save, in that href="" references the current page.

I assume that all browsers adhere to this, but this is just an educated guess. The HTML5 spec also allows empty URLs.

Edit: To meet the updated question, (almost) removing the query string can be done with href="?".

like image 45
Boldewyn Avatar answered Oct 12 '22 20:10

Boldewyn