0

Let's suppose we have this js function into a local file, no server involved:

function splitView()
{
    var tgtSrc = location.href;
    var frameset =  '<frameset rows="*,*">' +
                        '<frame name="' + upFrame + '" src="' + tgtSrc + '">' +
                        '<frame name="' + dwFrame + '" src="' + tgtSrc + '">' +
                    '</frameset>';
    document.write(frameset);   
}

that creates two named frames with the same document loaded.

Is that possible to synchronize 2 frames (not iframes!) content without reloading the document? Or at least is it possible to send data or any kind of signal from one frame to another to let the upFrame now that there are edits into the dwFrame that need to be loaded into its own content?

I know that there are limitations due to same origin policy while trying to get data from another frame, but in this case I want the dwFrame to send some message to the upFrame (I don't care about old browser compatibility just standard and modern ones).

Why I'll use it?

I have a bunch of tables into a LOCAL html file (no web server involved) that loads data from a csv file and I need to compare data from different points or to keep the header fixed on top while scrolling the rest of a specific table table or while inserting new data in one of them.

Edit of 17.02.2018

I'd try to implement a sync procedure using the session storage. What do you think?

Edit of 18.02.2018

Constraints:

  1. The ideal solution has to: Grant automatic synchronization between two frames
  2. The synchronization has to be bidirectional: if the user modify data into one frame the other get in sync, doesn't matter what frame is the origin and what the destination
  3. It doesn't affect too much browser performances
  4. The sync event is fired only if and when needed (when data into one frame or the other has changed)
halfer
  • 19,824
  • 17
  • 99
  • 186
willy wonka
  • 1,440
  • 1
  • 18
  • 31
  • Possible duplicate of [Invoking JavaScript code in an iframe from the parent page](https://stackoverflow.com/questions/251420/invoking-javascript-code-in-an-iframe-from-the-parent-page) –  Feb 16 '18 at 15:41
  • @ProfessorAllman Sorry but I don't agree: this post is not a possible duplicate, because the other post talks about iframes and this talks about frames: I edited this post to clarify the point – willy wonka Feb 16 '18 at 15:43
  • Ah didn't notice, [frames are deprecated](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/frame) in HTML5 and probably should not be used. iframes are still around. –  Feb 16 '18 at 15:50
  • So if it is different domains, than you need to have the ability to add code to each domain so they can talk. Are you in control of both domains? – epascarello Feb 16 '18 at 15:56
  • @epascarello al the code is in a single local file, no server involved... I've edited the original post to make clearer and to specify the aimed use – willy wonka Feb 16 '18 at 18:37
  • I did a bunch of tests and I'm going to think I need an intermediary object: something both frames of the same document can access to, to save data to and to retrive data from... to use for synchronization. So IMHO should be much better to have a **split-view** feature available directly on browsers, as it has for instance MS Excel that allows to view 4 different parts of the same spreadsheet at the same time. Some browsers already implement such a feature: and IMHO should be present in all modern browsers. – willy wonka Jul 04 '23 at 00:48
  • Well put a proposal in. You have been working on this for 5 years now? – epascarello Jul 04 '23 at 13:41
  • @epascarello, ...5 years...? No not for 5 years, but I found a possible work around but it is an ugly one and I actually don't like it because uses old fashioned html frames that are out of the game with html5. The solution I found is to crate a frame set and load in each frame an instance of the document. When the document is edited saves a copy its content into the local storage from where it is picked from the other frame by javascript. Each frame has an input event that is triggered when the innerText is modified and saves it to local storage and a local storage change event that... – willy wonka Jul 04 '23 at 16:36
  • @epascarello, ... gets back the data from storage from the other frame and puts back into its elements innerText. But as I said it is an ugly solution that has lots of problems. But I have some good news: some browser dev team (plugins devs and even Maxthon browser devs) are starting to implement a SplitView function. So **I hope in near future such function will be available in all browsers for both uses: to see different documents in a split screen and to see different parts of the same document in a Split View without usiing html frames but browser native split panels. – willy wonka Jul 04 '23 at 16:42

0 Answers0