无法在Chrome中访问其他框架的内容 [英] Can't access content of another frame in Chrome

查看:179
本文介绍了无法在Chrome中访问其他框架的内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个框架。两个帧中的页面来自同一个域(localhost或活动域 - 都使用相同的协议)。

第一帧需要访问第二帧中的元素frame(xsample),当它完全加载并且任何onload JS函数完成时。

 < frameset cols =*,*rows =*border =0framespacing =0> 
< frame src =picker.aspname =xpickerframeborder =nomarginwidth =15marginheight =15>
< frame src =doc.aspname =xsampleframeborder =nomarginwidth =15marginheight =15>
< / frameset>

以下代码适用于IE和Firefox,但不适用于Chrome或Safari,在 parent.xsample 始终为false

  function startWork(){
if isSurveyLoaded()== false){
SL = setTimeout(startWork(),1000);
return;
}
else {
setTimeout(doMoreWork(),2000);



函数isSurveyLoaded(){
if(!parent.xsample){
return false;
}
if(!parent.xsample.self.name){
return false;

if(parent.xsample.document.readyState!='complete'){
return false;
}
else {
return true;
}
}


解决方案

parent.frames [xsample] 来访问框架。

隐式引用全局对象上的命名元素不是标准化的。

在另一个笔记中,千万不要做 setTimeout(doMoreWork(),1000)使用eval来执行代码。

使用 setTimeout(doMoreWork,1000)这是正确的方式来做到这一点。


I have two frames. The pages in both frames come from the same domain (either localhost or a live domain - both using the same protocol).

The first frame needs to access elements of the second frame (xsample) when it's fully loaded and any onload JS functions have completed. But the second frame takes a while to load.

<frameset cols="*,*" rows="*" border="0" framespacing="0">
    <frame src="picker.asp" name="xpicker" frameborder="no" marginwidth="15" marginheight="15">
    <frame src="doc.asp" name="xsample" frameborder="no" marginwidth="15" marginheight="15">
</frameset>

The code below works in IE and Firefox but not in Chrome or Safari, In those parent.xsample is always false

function startWork(){
if(isSurveyLoaded()==false){
    SL=setTimeout("startWork()",1000);
    return;
}
else{
    setTimeout("doMoreWork()",2000);
}
}

function isSurveyLoaded(){
    if(!parent.xsample){
        return false;
    }
    if(!parent.xsample.self.name){
        return false;
    }
    if(parent.xsample.document.readyState!='complete'){
        return false;
    }
    else{
        return true;
    }
}

解决方案

Use parent.frames["xsample"] to access the frame.

Implicit references to named elements on the global object is not standardized.

On a different note, never do setTimeout("doMoreWork(), 1000)" as this forces the VM to use eval to execute the code.
Use setTimeout(doMoreWork, 1000) which is the proper way to do it.

这篇关于无法在Chrome中访问其他框架的内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆