【问题标题】:Redirects with Javascript and http-equiv使用 Javascript 和 http-equiv 重定向
【发布时间】:2011-03-24 07:14:10
【问题描述】:

我正在使用 Javascript 和邪恶的 http-equiv 元标记将旧博客重定向到新博客。为了防止机器人重复,我还添加了:

<meta name="robots" content="noindex" />

重定向sn-ps如下:

<!--Execute javascript rediect-->
<script type="text/javascript"><!--//--><![CDATA[//><!--
var url = "http://new_loc.blogspot.com/"
(document.images) ? location.replace(url) : location.href = url;
//--><!]]>
</script>
<!--If the browser can be bothered to refresh with new content,
also works if browser has javascript disabled, in mozilla family -->
<meta http-equiv="refresh" content="0;URL=http://new_loc.blogspot.com/" />

然而,这会将深层链接重定向到 new_loc 的首页,这可能会使传入的读者迷失方向。我希望 javascript 和 http-equiv 技巧的相对链接保持不变。实现这一目标的最佳方法是什么?

【问题讨论】:

    标签: javascript html redirect


    【解决方案1】:

    使用javascript重定向到新网址的类似脚本怎么样:

    <script>
    var myUrl = location.href;
    var old = /http:\/\/old_loc.blogspot.com/gi;
    var new1='http://new_loc.blogspot.com';
    myNewUrl = myUrl.replace(old, new1);
    window.location = myNewUrl;
    </script>
    

    甚至是Short CUT:

    <script>
    var old = /http:\/\/old_loc.blogspot.com/gi;
    var new1='http://new_loc.blogspot.com';
    window.location = window.location.href.replace(old, new1);
    </script>
    

    【讨论】:

      猜你喜欢
      • 2016-10-02
      • 1970-01-01
      • 2012-03-07
      • 2021-01-08
      • 2011-03-24
      • 1970-01-01
      • 2013-12-27
      • 1970-01-01
      • 2017-02-03
      相关资源
      最近更新 更多