【发布时间】:2013-12-17 02:46:52
【问题描述】:
点击<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/alert.php?id=1
这意味着它不是从基本标记中获取基本 URL,而是使用相对路径。
有什么想法吗?
【问题讨论】:
标签: javascript jquery html redirect window.location