为什么在超链接中使用window.location?

Bra*_*don 8 html javascript c# asp.net

我正在浏览一个我接管的网站,并在其中一个页面中看到了这一部分:

<a href="javascript:window.location='<%=GetSignOutUrl()%>';">
  // img
</a>
Run Code Online (Sandbox Code Playgroud)

显然,任何曾经使用过没有javascript网站的人都无法正常退出(令人惊讶的是,这种情况从未出现过).

所以首先想到的是

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

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.

Whi*_*hit 3

有以下三种可能:

  1. 开发人员试图在向用户发送之前强制使用 JavaScript。
  2. 开发人员试图屏蔽链接中的 href。也许这是因为它不能被有效地抓取,或者状态栏与它有关。
  3. 开发商是一个不墨守成规的人。

我会把它拆下来,看看它是否破裂。但话又说回来,我是一个墨守成规的人。