Rectangle 27 1

javascript Java Script, Difficulty getting list of all nested frames in page?


$(window).load(function(){
    ...
window.onload = function(){
    ...

Can you also take a look on thing I came across by the way of trying to solve my problem, I mean document.addEventListener does not work while using on document that consist only of frameset, and share your thoughts about it?

The load event fires at the end of the document loading process. At this point, all of the objects in the document are in the DOM, and all the images, scripts, links and sub-frames have finished loading.

The problem is the event on which you call this. $(document).ready() is fired when the current DOM has been loaded. So it's triggered when the 3 main frames are loaded. But at this point these frames didn't load their iframes yet. By changing the event to window.onload, you should have the expected result. Like this:

The problem with keydown listener (or any event that you apply on window or document), is that these events will be triggered on one of the sub frames, not on the top window. You could add these events on these sub frames, but you'll still need them to be loaded, so your back with the same problem.

Note
Rectangle 27 1

javascript Java Script, Difficulty getting list of all nested frames in page?


In order to access content of child frame, Same-Origin policy must be invoked.

Please see the following demo: frameset Demo. I have modified htm files. The idea is to listen to frameset onload event and access its contents after onlnoad event is fired.

Thanks for answer, thing is that dealing with frames is not up to me, i try to improve user side of existing system with web interface. So in fact I'm forced to deal with bunch of nested frames.

frameset is not supported in html5.

Note
Rectangle 27 1

javascript Java Script, Difficulty getting list of all nested frames in page?


<!DOCTYPE HTML Frameset DTD>
<html>
<head>
<script>
window.onload = function()
{
    var allFrames = [];
    function recursFrames(context)
    {
        for(var i = 0; i < context.frames.length; i++)
        {
            console.log(context.frames[i].name + " -- " + context.frames[i].location.href);
            allFrames.push(context.frames[i]);
            recursFrames(context.frames[i]);
        }
    }
    recursFrames(window);
    console.log("Frames count: " + allFrames.length);
}
</script>
</head>
<frameset cols="25%,*,25%">
  <frame id="frmain1" name="main1" src="frame0_1.htm">
  <frame id="frmain2" name="main2" src="frame0_2.htm">
  <frame id="frmain3" name="main3" src="frame0_3.htm">
</frameset>
</html>
frameset

I didn't do anything with shortcut key handler, but you said this was secondary and I'm not clear on what you are doing there.. sounds like you were just trying to use it for testing, but please let me know if you are still having trouble with this. Also, this solution uses native javascript, but you can of course replace with jQuery if desired.

Makes sense - I have run into similar situations myself when updating legacy products. Thanks for satisfying my curiosity. Let me know if you have any issues with the solution.

Thanks for your answer, thing is I'm improving some existing web app that is based on frames - i don't have access to source itself only way i can improve it is with GreaseMonkey and user defined script - so that is why I'm insisting on dealing with frames instead of iframes. And yes because of jQuery flexibility i will use it instead native JS. Thanks once again!

This writes to the console just to show you what is going on, but of course you can do whatever you want with this information. It creates a flat list (array) of all child frames, but you could structure it hierarchically if you like, or whatever.

Use a recursive function and the window load event, like so (works in latest versions of Chrome, FireFox and Edge; didn't test others. Probably works in IE5+ also).

You are using the HTML5 DOCTYPE, but frameset is not supported by HTML5. But it is up to the browser to decide when to stop supporting this, and many of them still do. I recommend you stop using frameset ASAP. Use iframe instead if you need frame-like behavior (different windows and documents).

Note