By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
426,045 Members | 1,743 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 426,045 IT Pros & Developers. It's quick & easy.

insert html table in iframe

P: 25
I have been trying for many years to insert my html table into the lower main iframe with no success. Here is my javascript code:

Expand|Select|Wrap|Line Numbers
  1. <a href="javascript:Display_Table()" target="main">Constellations</a>
  2.  
  3. <script type="text/javascript">
  4. function Display_Table(){
  5. var numOfCells = 88; 
  6. var columns = 8, rows = Math.ceil(numOfCells / columns), content = "", count = 0;
  7. content = "<table border='1' cellspacing='1' cellpadding='5'>";
  8. for (r = 0; r < rows; r++) {
  9.    content += "<tr>";
  10.    for (c = 0; c < columns; c++) {
  11.       content += "<td><a HREF='javascript:DisplayConstellations(" + count + ");'>" + ConName[count] + "</a></td>";
  12.       if (count == numOfCells)break;  // here is check if number of cells equal Number of Pictures to stop
  13.       count++;
  14.    }
  15.    content += "</tr>";
  16. }
  17. content += "</table>";
  18. document.body.innerHTML = content; 
  19. }
  20. </script>
1 Week Ago #1

✓ answered by gits

in the code you call a method: DisplayConstellations which is assigned to an anchor tag somehow instead of an onclick-event. probably you need to check that function's code.

Share this Question
Share on Google+
7 Replies


gits
Expert Mod 5K+
P: 5,282
what happens at the moment? the html you create in the function is replacing the content of your window - since you get a reference to the window's document and tell the code to do so with:

Expand|Select|Wrap|Line Numbers
  1. document.body.innerHTML = content;
you cannot target javascript code with a links target-attribute - javascript would need to reference the correct window and then the document in that window. you can use the frames property of your top.window for example to achieve that.
1 Week Ago #2

P: 25
I have 2 iframes one for the horizontal menu and the other is underneath the menu iframe to recieve whatever is selected from the menu. I just need some sample code to insert the 88 cells into the iframe so the User can click on a cell and let the corresponding listing appear where the table was. I used to do this before html 5 came out but now I have no idea as to what code I need to use. I am an 81 year old retired vb6 programmer and I am out of touch with the latest methods to use iframes. Thank you for your reply. John
1 Week Ago #3

gits
Expert Mod 5K+
P: 5,282
there is not something about latest methods to use frames - except may be to not use any frames at all - everything is usually achieved with css today. for a simple example on how to access an iframe you can start from here:

https://www.w3schools.com/jsref/prop...ntdocument.asp
1 Week Ago #4

P: 25
I tried the w3schools.com but no one seems to understand that all I want to do is insert my html5 table into iframe and keep the iframe away from the top iframe.
6 Days Ago #5

gits
Expert Mod 5K+
P: 5,282
in the example there the background color of the iframe is set - you can use the same method to reference the iframe's document to set any other content there
6 Days Ago #6

P: 25
I managed to get the table into the iframe but the table erased the menu. when I clicked the cell to start a listing the list went to another page.
5 Days Ago #7

gits
Expert Mod 5K+
P: 5,282
in the code you call a method: DisplayConstellations which is assigned to an anchor tag somehow instead of an onclick-event. probably you need to check that function's code.
5 Days Ago #8

Post your reply

Sign in to post your reply or Sign up for a free account.