How to remotely use methods of an instance from another html frame

How to remotely use methods of an instance from another html frame

Hi,

I'm looking for a solution to change the selection of a tree item by clicking into a text content frame.
Just to explain:

I have 3 html files:
- 1 HTML with the FrameSet
  1. <html xmlns="http://www.w3.org/1999/xhtml">
  2.   <head>
  3.     <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
  4.     <title> This is my title  </title>
  5.     </head>
  6.   <frameset cols="20%,*">
  7.     <frame src="src/index_toc.html" name="tocframe" id="tocframe" />
  8.     <frame src="src/index_main.html" name="main_content" id="main_content" />
  9.   </frameset>
  10. </html>
- them 2 Simple HTML Files 
      toc has the tree -->  tocframe
       index_main is just the content to read, with several chapters -->  main_content

So in the toc file there I use the "fancytree ( https://github.com/mar10/fancytree/wiki)"
  1.  <script type="text/javascript">
  2.       var mytoc= $(function(){
  3.       // Create the tree inside the <div id="tree"> element.
  4.      $("#toc").fancytree({
  5.           activeVisible: true, // Make sure, active nodes are visible (expanded).
  6.           aria: false, // Enable WAI-ARIA support.
  7.           autoActivate: true, // Automatically activate a node when it is focused (using keys).
  8.           autoCollapse: true, // Automatically collapse all siblings, when a node is expanded.
  9.           autoScroll: false, // Automatically scroll nodes into visible area.
  10.           clickFolderMode: 4, // 1:activate, 2:expand, 3:activate and expand, 4:activate (dblclick expands)
  11.           checkbox: false, // Show checkboxes.
  12.           debugLevel: 2, // 0:quiet, 1:normal, 2:debug
  13.           disabled: false, // Disable control
  14.           focusOnSelect: false, // Set focus when node is checked by a mouse click
  15.           generateIds: false, // Generate id attributes like <span id='fancytree-id-KEY'>
  16.           idPrefix: "ft_", // Used to generate node id´s like <span id='fancytree-id-<key>'>.
  17.           icons: false, // Display node icons.
  18.           keyboard: true, // Support keyboard navigation.
  19.           keyPathSeparator: "/", // Used by node.getKeyPath() and tree.loadKeyPath().
  20.           minExpandLevel: 1, // 1: root node is not collapsible
  21.           quicksearch: false, // Navigate to next node by typing the first letters.
  22.           selectMode: 2, // 1:single, 2:multi, 3:multi-hier
  23.           tabbable: true, // Whole tree behaves as one single control
  24.           titlesTabbable: false, // Node titles can receive keyboard focus
  25.           activate: function(event, data) {       
  26.             var node = data.node;        // Use <a> href and target attributes to load the content:        
  27.             if( node.data.href ){          // Open target          
  28.               window.open(node.data.href, node.data.target);          // or open target in iframe//         
  29.               $("[name=main_target]").attr("src", node.data.href);       
  30.             }    
  31.           }
  32.       });
  33.     });
  34.   </script>
so now on the content (index_main) I want to change the selected tree items by clicking into the text content.
So when I click somewhere in chapter 2 section 1.1 the tree item 2.1.1 in the toc frame will be selected.

  1. function add_highlighter() {
  2.   filename = "" + window.location.pathname.substr(window.location.pathname.lastIndexOf("/") + 1);
  3.   element = document.getElementsByTagName("div");
  4.   for (var i = 0; i < element.length; i++) {
  5.     p = element[i].className + "";
  6.       if (p == "chapter" || p == "book" || p == "preface" || p == "section" || p == "appendix" || p == "index") {
  7.        element[i].onmouseup = function () {
  8.        //alert(filename + "#" + this.getElementsByTagName("a")[0].id);
  9.         var frameDocument = $('frame[name="tocframe"]', top.document)[0].contentDocument;
  10.         var myTree = $('mytoc',frameDocument);
  11.         node = myTree.fancytree("getActiveNode");
  12.         node.setTitle("New title");
  13.       };   
  14.     } 
  15.   }
  16. }
I was able to change the backgroundcolor by using the frameDocument but I struggle with the instance of the fancytree.

So is it possible what I'm trying  to do?
Best regards

Markus