Unable to access the contents of another frame in Chrome

I have two frames. Pages in both frames come from the same domain (either local or live domain - both using the same protocol).

The first frame should access the elements of the second frame (xsample) when it is fully loaded, and all the JS functions to load. But the second frame takes some time 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 these parent.xsample 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; } } 
0
source share
4 answers

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

Implicit references to named elements of the global object are not standardized.

In another note, never do setTimeout("doMoreWork(), 1000)" , as this forces the virtual machine to use eval to execute code.
Use setTimeout(doMoreWork, 1000) , which is the right way to do this.

+1
source

I solved this:
1. Providing the target frame with both a name and id name 2. testing for both 3. Verifying that the variable (finishedLoading) in the target frame was set to true
(code changed to use === instead of == loading completed during testing)

 function isSurveyLoaded(){ if(!(parent.frames["xsample"] || parent.document.getElementById('xsample'))){ return false; } else{ if(parent.frames["xsample"]){ target=parent.frames["xsample"]; } else{ target=parent.document.getElementById('xsample'); } } if ((target.finishedLoading==='undefined') || (target.finishedLoading===false) ){ return false; } else{ return true; } } 

Now simplified with

 <frame src="doc.asp" onload="frameisloaded(this)" name="xsample" id="xsample" frameborder="no" marginwidth="15" marginheight="15"> 
0
source

In Chrome, a Window object is accessed by window.frames [index], from which you can access good materials such as a document inside this frame content.

Accessing it using document.getElementById returns only the iframe itself, with virtually no useful attributes for further searches in the DOM.

This error is that you cannot access the Window object by its name using window.frames [name], as other browsers do!

0
source

To refer to comments on anti-frames: a critical attitude towards those who use frames does not answer the question. Secondly, there are things that make frames better than any other alternative.

Therefore, the question should not be: "What self-respecting web developer uses frames?" It should be: "Which self-respecting full-featured browser doesn't support them properly?" and one answer is obviously Chrome.

They sprinkled “safety flags” around various functions in their interpreter, including those that facilitate the transfer of certain information between pages in different frames. Therefore, such things do not work on local startup:

top.frames [2] .document.getElementById (ID)

However, when run on the server, it usually works fine.

If you need it to work locally in Chrome, you need to use some kind of workaround. You must be creative. In some cases, for example, when you know the situation variables, you can create an array to handle various possibilities (which is drag and drop, when otherwise it should not be so complicated).

0
source

Source: https://habr.com/ru/post/1388329/


All Articles