views:

115

answers:

4

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.

A: 

It could be because multiple domains possibly are used and which one was unclear or not easily available in the code?

spig
but that would have been accounted for by the `<%=GetSignOutUrl()%>` anyway. `<%=GetSignOutUrl()%>` only returns a URL (by the looks of it) because `javascript:window.location` needs a URL to function
DaveDev
Yeah, and you could also have a relative sign-out link which wouldn't bother with the domain.
spig
+1  A: 

My guess is that if the developer didn't know to consider the client's capability of executing javascript, they might not have known what a href is. It's unlikely but not impossible.

DaveDev
+3  A: 

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.

Whit
I agree with point 2, on the condition that instead of point 3's "non-conformist" be changed to "non-competent" (I love coining ironic terms :-) ) ... anyway the reason I agree with point two is that maybe they don't know what a Robots.txt file is, and this is the only way they could prevent Google from constantly trying to log out?
DaveDev
A: 

This might be an attempt to hide the link from search engines.

SLaks