【问题标题】:ie vs chrome window.location.href and <base> tagie vs chrome window.location.href 和 <base> 标签
【发布时间】:2013-12-17 02:46:52
【问题描述】:

点击&lt;td&gt; 后,我在使用javascript 重定向到不同页面时遇到问题。对于我的网站,我使用&lt;base href=""&gt; 标签作为链接的起点。

所以考虑一下这段代码:

<!doctype html>
<html lang="en"><head>
    <meta charset="utf-8"/>
<title>Login</title>
<base href="http://www.mysite.com/MyWebsite/manage/" />

特别参考&lt;base href="http://www.mysite.com/MyWebsite/manage/" /&gt;

并考虑这个 jQuery:

//Set row clicking
    $('table#alerts_table').on("click", "td", function () {
        var alert_id = $(this).closest('tr').find('input[type=checkbox]').val();
        var href = 'alerts/alert.php?id=' + alert_id;
        if (href) { window.location.href = href; }
    });

特别参考

var href = 'alerts/alert.php?id=' + alert_id;
if (href) { window.location.href = href; }

并认为我当前在网站上的位置已经在名为 alerts 的文件夹中,如下所示: http://www.mysite.com/MyWebsite/manage/警报/index.php

我想从 index.php 移动到 alert.php。

在 chrome 上,所有工作都按预期工作,即基本 href http://www.mysite.com/MyWebsite/manage/ 连接到 alerts/alert.php?id=1 并且我被相应地重定向。

但是在 IE 中 文件夹警报加倍:http://www.mysite.com/MyWebsite/manage/alerts/alerts/alert.php?id=1

这意味着它不是从基本标记中获取基本 URL,而是使用相对路径。

有什么想法吗?

【问题讨论】:

    标签: javascript jquery html redirect window.location


    【解决方案1】:

    你可以使用:

       document.location.replace(); 
    

    功能。您不需要使用基本选项。它将被重定向到同一目录中的页面或子目录。

    【讨论】:

      猜你喜欢
      • 2015-05-22
      • 2010-12-12
      • 2010-09-27
      • 2023-03-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-08-24
      • 2011-09-17
      相关资源
      最近更新 更多