0

我正在尝试让 lightbox2 与我的网站 http://www.therussianfrostfarmers.com/一起工作 ,但是我似乎遇到了外部 js 文件冲突的问题。我不完全确定我知道这段代码的问题出在哪里,但我相信它与 onload 事件的调用方式有关。主页上的博客内容被加载到 iframe 中,iframe 使用 onload 事件动态调整大小以适应内容,但是当我导入 lightbox2 所需的文件时(按正常方式)....

<script type="text/javascript" src="js/prototype.js"></script>
<script type="text/javascript" src="js/scriptaculous.js?load=effects,builder"></script>
<script type="text/javascript" src="js/lightbox.js"></script>

....它取消了我在 iframe 上调用的 updateSize()。lightbox2 仍然有效。

我已将有问题的 js 文件缩小到prototype.js。

我尝试使用函数 dhtmlLoadScript() 处理事件序列。使用以下代码,页面加载正确,iframe 正确调整大小,但随后页面变为白色,firefox 加载图标一直在旋转。

<script type='text/javascript'>
// function to resize iframe
function updateSize() 
{ 
    // get width
    frame_x = $('#content').width() -5; 

    // apply width 
    $('#iframed').css('width', frame_x); 


    //get height
    var the_height = document.getElementById('iframed').contentWindow.document.body.scrollHeight +120;

    //apply height
    document.getElementById('iframed').height = the_height;

}

// function to load external js files 
function dhtmlLoadScript(url)
{
   var e = document.createElement("script");
   e.src = url;
   e.type="text/javascript";
   document.getElementsByTagName("head")[0].appendChild(e);
}

// function to handle each event on onload callback 
function callbackHandler()
{
   updateSize();
   dhtmlLoadScript("http://www.therussianfrostfarmers.com/ndxz-studio/site/js/prototype.js");
   dhtmlLoadScript("http://www.therussianfrostfarmers.com/ndxz-studio/site/js/scriptaculous.js?load=effects,builder");
   dhtmlLoadScript("http://www.therussianfrostfarmers.com/ndxz-studio/site/js/lightbox.js"); 
} 

</script>

<iframe src='$url' frameborder='0' id='iframed' onload="callbackHandler()"></iframe>

抱歉,如果有任何不清楚的地方。

谢谢凸轮

4

1 回答 1

0

快速检查一下,看看函数名 updateSize() 是否没有在原型中重新映射

于 2009-06-10T07:36:00.260 回答