多窗口打开在IE中不起作用


Multiple window.open not working in IE

我有一个 ahref,点击时会更改 3 个 iFrame 的内容。代码如下:

<a href='weekone.php' target='weekone' onclick='window.open("weektwo.php","weektwo"); window.open("weekthree.php","weekthree")'>Link</a>

现在这在Firefox,Safari等中完美运行,但在IE中不起作用。谁能为我阐明这个问题?我不能使用Javascript,因为我在PHP框架中工作,并且iFrame链接是从数据库中调用的。

更新

问题似乎出在从 window.open 调用的 URL 中的空格!当我从数据库中调用信息时(即 - "第二周.php?名称=鲍勃和戴夫")我该如何解决这个问题?

什么版本的IE?

在IE 8上测试,效果很好。

<a href='test.htm' target='weekone' onclick='window.open("test.htm","weektwo"); window.open("test.htm","weekthree")'>Link</a>
<iframe name='weekone' id='weekone' width=100 height=100></iframe>
<iframe name='weektwo' id='weektwo' width=100 height=100></iframe>
<iframe name='weekthree' id='weekthree' width=100 height=100></iframe>

如果您尝试在<iframe>中打开链接,这可能更容易做到

document.querySelector('iframe[name="weekone"]').src='test.htm';
document.querySelector('iframe[name="weektwo"]').src='test.htm';
document.querySelector('iframe[name="weekthree"]').src='test.htm';

(我使用过document.querySelector,因为它是最简单的,但当然你可以使用document.getElementById或任何你想要的方式来获取对<iframe>的引用。

在注释的背面,尝试在 onclick 的末尾添加"return true;"(未经测试)...

<a href='weekone.php' target='weekone' onclick='window.open("weektwo.php","weektwo"); window.open("weekthree.php","weekthree"); return true;'>Link</a>

更新

根据更新的问题,尝试使用 PHP 函数"htmlentities"对查询字符串进行"HTML 编码"。

我基于您的原始(预编辑)代码进行以下操作。 所以在这种情况下,我很抱歉要求您编辑它,但我确实要求您准确显示发送到浏览器的内容......

<a href='weekone.php?Name=<?=htmlentities($i[Name])?>' target='<?=$i[Name]?> weekone' onclick='window.open("weektwo.php?Name=<?=htmlentities($i[Name])?>","<?=$i[Name]?> weektwo"); window.open("weekthree.php?Name=<?=htmlentities($i[Name])?>","<?=$i[Name]?> weekthree")'>Link</a>

更新2(由于我很愚蠢)

它不应该是"HTML编码",而应该是使用"urlencode"的"URL编码"......

<a href='weekone.php?Name=<?=urlencode($i[Name])?>' target='<?=$i[Name]?> weekone' onclick='window.open("weektwo.php?Name=<?=urlencode($i[Name])?>","<?=$i[Name]?> weektwo"); window.open("weekthree.php?Name=<?=urlencode($i[Name])?>","<?=$i[Name]?> weekthree")'>Link</a>