Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why use window.location in a hyperlink?

I was going through a website I've taken over and came across this section in one of the pages:

<a href="javascript:window.location='<%=GetSignOutUrl()%>';">
  // img
</a>

Apparently anyone who has ever used the site without javascript would not be able to log out properly (surprisingly enough, this has never come up).

So the first thing that comes to mind is

<a href="<%=GetSignOutUrl()" onclick="javascript:window.location='<%=GetSignOutUrl()%>';">
   // img
</a>

Then I realized I don't know why I'm keeping the javascript call around at all. I'm just a little confused as to why it would have been written like that in the first place when a regular link would have worked just fine. What benefit does window.location have over just a regular link?

This is also the only place in the website I've seen something like this done (so far).

Edit: The programmer before me was highly competent, which is actually why I was wondering if there was something I wasn't taking into account or if he just made a simple oversight.

like image 459
Brandon Avatar asked Aug 13 '10 21:08

Brandon


1 Answers

There are three possibilites:

  1. The developer was trying to enforce Javascript use before sending the user along.
  2. The developer was trying to mask the href in the link. Perhaps this was so it wouldn't be crawled effectively, or the status bar had something to do with it.
  3. The developer was a non-conformist.

I would remove it and see if it breaks. But then again, I'm a conformist.

like image 117
Whit Avatar answered Oct 03 '22 19:10

Whit