簡體   English   中英

多個window.open在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中包含空格! 當我從數據庫中調用信息時(即-“ weektwo.php?Name = Bob和Dave”),如何解決此問題?

在評論的后面,嘗試添加“ 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>

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

什么版本的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>引用的方式。)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM