Setting href to blank issue RRS feed

  • Question

  • User438705957 posted

    I had an anchor element styled as a button for the users to click on to log out.
    I needed to kill a few things on the server, so the onclick event caused a function to be run on the front-end which generated an AJAX call to the server to kill off those things. I set href="" thinking it was not needed.

    When Users clicked on the button, the page was reloading and showing the login screen again.

    I had several attempts to fix it, steeping through a thousand debug sessions and just couldn't crack it.

    Finally I got the idea to to remove href="" and heh presto, it fixed the issue.

    On investigation, I found that setting href="" causes a page reload.

    I'm posting this here in order to save other programmers the pain I went through in diagnosing the problem.

    Tuesday, October 20, 2020 10:33 PM

All replies

  • User753101303 posted


    It is quite expected if you think about it. This is similar to dir or dir "" that shows the content of the current location.

    My guess is that you selected a control having the closest appearance you want rather than the closest behavior and ended up in having both to customize the appearance and behavior?

    IMO the real trick here could be to always select the control with the closest behavior you want even if it requires more styling. Why to use an anchor or hyperlink if you wanted this to behave and maybe look like a button?

    Wednesday, October 21, 2020 12:18 PM
  • User438705957 posted

    That’s a good guess.

    i picked the anchor tag because the element was surrounded by other anchor tags, with no extra behaviour required, and it just fit the styling neatly.

    i take your point, I did take the path of least resistance.


    Wednesday, October 21, 2020 5:52 PM