我在使用JavaScript时,希望通过点击一个来将页面重定向到不同的页面,但遇到了问题。我的网站中使用标签作为链接的起始点。
请考虑以下示例代码:
<!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/alerts/index.php。
我想从index.php移动到alert.php。
在Chrome浏览器中,所有内容都按照预期工作,即将基本href http://www.mysite.com/MyWebsite/manage/
连接到alerts/alert.php?id=1
,并且我会被相应地重定向。
然而,在IE浏览器中, 文件夹"alerts"被重复了: http://www.mysite.com/MyWebsite/manage/alerts/alerts/alert.php?id=1
这意味着它并没有从基本标记中获取基本URL,而是使用相对路径。
有任何想法吗?