Not a complete solution, but there are errors in your code:
var needfooter;
The variable is not initialized (well it will be because your loop always ends at i == 87). But in that case, the remaining logic is somewhat flawed.
if (i % 8 == 8){ ... }
That condition will never be true since % will returns a value between 0 and 7 inclusively.
Thus in the end, you don't always get the expected output.
By the way, your condition are also broken. If the last i is 87, then it is that last cell in that row and you don't need the footer in that case.
Thus you get a table with unmatched and
. Invalid HTML code might not always display what you want on all browsers.
In your prefered browser, display source code and verify it and fix code accordingly.
By the way, it would be a good idea to write unit test code for that and validate that you get the intended output for any size. You should test edge cases...
Update
If your problem is about where the content is displayed, then remove unrelated stuff from your question (see comment below).
By the way, if you are in a iframe, then all JavaScript code will relate to that iframe. As far as I know, you cannot access the outer frame from code. The only thing you could do is to open a link in top windows. Still your sample code do not show that you have an iframe.