星期六, 11月 08, 2008

JavaScript redirects

JavaScript offers several ways to display a different page in the current browser window. Quite frequently, they are used for a redirect. However, there are several reasons to prefer HTTP header or the refresh meta tag (whenever it is possible) over JavaScript redirects:

  • There are several reasons for some users to disable JavaScript:
    • Security considerations
    • Some browsers don't support JavaScript
    • many crawlers (e.g. from search engines) don't execute JavaScript.
  • There is no "standard" way of doing it: A search for "you are being redirected" will find that virtually each JavaScript redirect employs different methods. This makes it difficult for Web client programmers to honor your redirect request without implementing all of JavaScript.

Frame redirects

A slightly different effect can be achieved by creating a single HTML frame that contains the target page:

<span class="sc2"><span class="kw2"><frameset</span> <span class="kw3">rows</span>=<span class="st0">"100%"</span><span class="kw2">></span></span>
  <span class="sc2"><span class="kw2"><frame</span> <span class="kw3">src</span>=<span class="st0">"http://www.example.com/"</span><span class="kw2">></span></span>
<span class="sc2"><span class="kw2"></frameset></span></span>
<span class="sc2"><span class="kw2"><noframes></span></span>
  <span class="sc2"><span class="kw2"><body></span></span>Please follow <span class="sc2"><span class="kw2"><a</span> <span class="kw3">href</span>=<span class="st0">"http://www.example.com/"</span><span class="kw2">></span></span>link<span class="sc2"><span class="kw2"></a></span></span>!<span class="sc2"><span class="kw2"></body></span></span>
<span class="sc2"><span class="kw2"></noframes></span></span>

One main difference to the above redirect methods is that for a frame redirect, the browser displays the URL of the frame document and not the URL of the target page in the URL bar.

This technique is commonly called cloaking. This may be used so that the reader sees a more memorable URL or, with fraudulent intentions, to conceal a phishing site as part of website spoofing.


Ref: wiki

0 意見: