【问题标题】:Multiple window.open not working in IE多个window.open在IE中不起作用
【发布时间】:2012-05-31 19:06:35
【问题描述】:

我有一个 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 中的空格!当我从数据库(即“weektwo.php?Name=Bob and Dave”)调用信息时,我该如何解决这个问题??

【问题讨论】:

  • 您是否有机会使用发送到 IE 的实际输出来更新问题? (用假的替换任何实际的 URL)
  • 你缺少一个 ;在第二个窗口之后。打开。可能是问题所在。顺便说一句,你正在使用 javascript。
  • 我不确定丢失的 ;这本身就是一个问题 - 但我会尝试在 onclick 的末尾放置一个“返回 true”(这 需要一个 ; 在第二个 window.open 的末尾)
  • @freefaller 这样更好吗?谢谢。还有埃里克,具体在哪里?我在这里添加了一个“第三周);”但是还是不行……
  • @freefaller 不是 100% 确定你的意思。可以举个例子吗?

标签: php html hyperlink href


【解决方案1】:

什么版本的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>

【讨论】:

  • 我的第一帧加载完美。这两个 window.open 命令不是...
  • 对不起,这里没有 IE9。但这似乎适用于旧版本的 IE。
  • 大多数 php 库都有转义 url 的方法。我认为这些空格应该是 '%20'。
  • 这看起来很神奇,但我完全不知道如何实现它...... :-S
  • 通过该函数传递您的 php 变量。类似
【解决方案2】:

如果您尝试打开 &lt;iframe&gt; 中的链接,这样做可能更容易

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 或任何您想获得对&lt;iframe&gt; 的引用的方式。)

【讨论】:

  • 请问我该如何实现呢?
  • 试试&lt;a href='weekone.php' target='weekone' onclick='document.querySelector('iframe[name="weekone"]').src='weekone.php';document.querySelector('iframe[name="weektwo"]').src='weektwo.php'; document.querySelector('iframe[name="weekthree"]').src='weekthree.php';return false '&gt;Link&lt;/a&gt;
【解决方案3】:

在 cmets 的背面,尝试添加“return true;”到 onclick 结束(未经测试)...

<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>

UPDATE 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>

【讨论】:

  • OK - 我认为问题在于您正在点击 IE“弹出窗口阻止程序”...在 IE8 上进行测试我得到第一个窗口,然后在顶部显示“弹出窗口被阻止”消息客户端窗口。我的猜测是你不会绕过这个(不要求用户允许弹出窗口)。
  • 还以为我是在 iFrame 中打开的?!
  • Doh...抱歉,我是个混蛋...我没注意到它是 IFrames...回到绘图板
  • @PhilHowell - 抱歉,我没有答案。像 numespascal 一样,我在 IE6 IE8(inc 兼容模式)和 IE9(inc 兼容模式)上进行了测试,但没有发现问题 - 不幸的是,我没有 IE7 可以测试
  • @PhilHowell - 你能帮我确认一件事吗......当你说它“不工作”时,可以是具体的。故障是 iframe 没有加载正确的内容,还是 iframe 甚至没有尝试加载任何内容?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-11-06
  • 2011-10-18
  • 2012-05-23
  • 2018-11-06
  • 2018-05-23
相关资源
最近更新 更多