0

i have a html template which uses js. I am trying to load an external .html file which contains a table into that html template with js. I am not running this stuff on a webserver.

In the html i have

<div id="table_placeholder">Load table heree</div>

I tried the following in my js:

jQuery(document).ready(function(){
     //load the html file
     document.getElementById("table_placeholder").innerHTML='<object type="text/html" data="Export.html" ></object>';
     //access the loaded table
     var title_column_1 = document.getElementById("data").rows[0].cells.item(0).innerHTML;
     alert(title_column_1 );
});

The table in the Export.html has the ID "data"

When the able is loaded the html looks like this: loaded html

But i am getting: Uncaught TypeError: Cannot read property 'rows' of null

I guess that i cannot access the html table i loaded with .innerHTML within the same js. Is there any way how could i achieve that? Or did i oversee something? Is it a problem with the order of loading all the stuff?

Michael
  • 13
  • 6
  • The issue is, that the file you load inside the `object` has its own `document`. You likely need something like [this](https://stackoverflow.com/questions/42267945/how-to-access-the-elements-of-the-html-loaded-in-object-tag). – Lain Jan 08 '21 at 12:58
  • thanks i will have a look at it – Michael Jan 08 '21 at 13:08
  • Sadly no success, still getting the same error. Any other tips? – Michael Jan 08 '21 at 13:30
  • Could it be true that this is not possible because i not using a webserver? – Michael Jan 08 '21 at 15:25

0 Answers0