4

这是javascript我目前正在使用的代码:

     function toggleContainer(containerID, hideContainerIDs) {
            if(hideContainerIDs) {
                for(var i=0; i<hideContainerIDs.length; i++) {
                    ajaxChat.showHide(hideContainerIDs[i], 'none'); 
                }
            }       
            ajaxChat.showHide(containerID);
            if(typeof arguments.callee.styleProperty == 'undefined') {
                if(typeof isIElt7 != 'undefined') {
                    arguments.callee.styleProperty = 'marginRight';
                } else {
                    arguments.callee.styleProperty = 'right';
                }
            }
            var containerWidth = document.getElementById(containerID).offsetWidth;
            if(containerWidth) {
                document.getElementById('chatList').style[arguments.callee.styleProperty] = (containerWidth+28)+'px';
                document.getElementById('chatBooth').style[arguments.callee.styleProperty] = (containerWidth+28)+'px';  
            } else {
                document.getElementById('chatList').style[arguments.callee.styleProperty] = '20px';
                document.getElementById('chatBooth').style[arguments.callee.styleProperty] = '20px';
            }

        }

DIV 和 IFrame 代码:

<div id="chatBooth" style="display:none; overflow: hidden;"> 
        <iframe style="overflow:hidden;height:100%;width:100%" height="100%" width="100%" frameborder="0" scrolling="no" name="booth" id="booth" src="about:blank">
        </iframe>
    </div>

我已经尝试了我能想到的一切,这段代码在每个浏览器中都有效,但是IE. 它所做的是,当您单击当前可见的窗口内的链接时,它会在 hidden 中加载一个新页面IFrame,并且您可以通过IFrame单击按钮使其可见。这是显示和隐藏隐藏DIV和的按钮IFrame

<input type="button" value="[LANG]toggleChat[/LANG]" title="[LANG]toggleTitleChat[/LANG]" alt="[LANG]toggleChat[/LANG]" onclick="ajaxChat.showHide('chatBooth', null);"/>   

这是Link更改应该位于IFrame每个浏览器中的内容的代码,但是IE

alert(this.channelName);
            document.getElementById('booth').contentWindow.location.reload(true);
            document.getElementById('booth').src = 'http://www.cnn.com';

上面的代码适用于除IE. 我完全不知所措。我花了几个小时Google搜寻,似乎找不到解决方案,甚至找不到导致问题的原因。任何帮助将不胜感激。

这是请求的 showHide 代码:

showHide: function(id, styleDisplay, displayInline) {
    var node = document.getElementById(id);
    if(node) {
        if(styleDisplay) {
            node.style.display = styleDisplay;
        } else {
            if(node.style.display == 'none') {
                node.style.display = (displayInline ? 'inline' : 'block'); 
            } else {
                node.style.display = 'none';
            }
        }   
    }
}

用于重新加载 iframe 和更改 iframe SRC 的代码

document.getElementById('booth').contentWindow.location.reload(true);
document.getElementById('booth').src = 'http://www.WEBSITE.com'+ ajaxChatConfig.loginChannelName +'/index.html';

上面似乎不允许 IE 在 IFrame 中加载任何内容,即使它被告知这样做。

4

1 回答 1

0

我复制了您提供的代码,并通过简单地更改您的一个函数来使其工作。但是,因为我没有您的代码的实际工作副本,所以我不能确定这对您是否有用......

我从此更改了 showHide 函数声明...

showHide: function(id, styleDisplay, displayInline) {

对这个……

function showHide(id, styleDisplay, displayInline) {

我使用的 HTML:

<body>
    <div id="chatBooth" style="display:none; overflow: hidden;width:100%;">
        <iframe style="overflow:hidden;height:100%;width:90%;border:1px solid red;" scrolling="no" name="booth" id="booth" src="http://www.ebay.com"></iframe>
    </div>

    <input type="button" value="toggleChat" title="toggleTitleChat" onclick="showHide('chatBooth', null);"/>
</body>

更新::

您可以使用此功能替换 document.getElementById('booth').contentWindow.location.reload(true);

function loadContent(passedInURL){
    if(!passedInURL){
        passedInURL = "http://www.ebay.com";
    }
    var theIFrame = "<iframe style='overflow:hidden;height:200px;width:90%;border:1px solid red;' scrolling='no' name='booth' id='booth' src='";
    theIFrame += passedInURL + "'></iframe>";
            document.getElementById('chatBooth').innerHTML= theIFrame;
}

并将此按钮添加到页面..

<input type="button" value="reLoad" title="reLoadFrame" onclick="loadContent();"/>
于 2013-01-17T02:01:54.407 回答