ie与chrome window.location.href和<基本>标签

ie vs chrome window.location.href and <base> tag

本文关键字:lt gt 标签 基本 chrome window location href ie      更新时间:2024-01-28

单击<td>时,我遇到了使用javascript重定向到其他页面的问题。对于我的网站,我使用<base href="">标签作为链接的起点。

所以考虑一下这个代码:

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

<base href="http://www.mysite.com/MyWebsite/manage/" /> 的特殊参考

并考虑这个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/aler.php?id=1

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

有什么想法吗?

您可以使用:

   document.location.replace(); 

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