View Full Version : ahh! error mesage re: object being NULL or not an object.

05-20-2011, 02:28 PM
I have a CLASSIC ASP in IE 8 that is using the winhttprequest object to get the contents of an "external" website (just a page from another department here.. but a different server).Then i modify the html i get to suit my needs.. save it to a file, and then finally, i display this stuff in an IFRAME. (i wrapped a div tag around the iframe so technically, i'm doing something like: "divtabframe.innerHTML = '<IFRAME SRC='myserver/somepage.html'></IFRAME>)

My problem is that when i refresh the main page, i want the iframe to also display the latest data. It does get the latest data from the external site and its saved in "somepage.html". But the iframe isn't updated unless i explicitly right-click inside the frame and manually select refresh. I have added a <meta http-equiv="refresh" content="30"> line to make it auto refresh on it's own. But the users find it annoying that the page refreshes while they're working on it. They prefer to have their own button that will refresh both the main page that gets the data, and the iframe to read the new file.

So far, I've been trying to see if i can get the iframe to refresh when the users click on the tab "buttons". But i'm getting an error that says:

"'document.getElementById(...).contentDocument.location' is null or not an object "

on the line where I'm trying to reload the iframe. (in bold italics below)
So... here's some snippets from my code.First thing i do before displaying anything is i get the data i need for the iframe from an external server. It creates a file on my local server.

<script type="text/javascript">
var tabs = new Array(
"Tab 1 Title|http://myserver/Dev/s/tab1.html|*",
"'Tab 2 Title'|http://myserver/Dev/s/tab2.html",);

var tabAlign = "LEFT";

function tabOnClick(ID){
var oElement = null;
for (var i = 0; i < tabs.length; i++)
oElement = document.getElementById(i);
oElement.className = "tabOff";
oElement = document.getElementById(ID);
oElement.className = "tabOn";
var tab = tabs.split("|");
divTabFrame.innerHTML = "<IFRAME SRC="+tab[1]+" ID=iframe"+ID+ " CLASS='tabFrame'></IFRAME>";

function tabLoad(){
var HTML = "";
HTML += "<P ALIGN="+tabAlign+">";
for (var i = 0; i < tabs.length; i++)
var tab = tabs[i].split("|");
HTML += "<INPUT TYPE='BUTTON' ID="+i+" CLASS='tabOff' VALUE="+tab[0]+" onClick='tabOnClick("+i+")'>&nbsp;";
divTabButtons.innerHTML = HTML;
for (var i = 0; i < tabs.length; i++)
var tab = tabs[i].split("|");
if (tab[2] == "*")
</script>And then later on, here's my code to display the iframe with divs.

<TD colspan="3" align="left">
<DIV ID="divTabButtons"></DIV>
<DIV ID="divTabFrame"></DIV>

I tried changing "document.getElementById
("iframe"+ID).contentDocument.location.reload(true); "


"document.getElementById("iframe"+ID).contentWindow.location.reload(true); "

but that didn't resolve my problem either. I also tried reloading the div tag that wraps around the frame instead.. but i get the same error message.

can someone either:
help me figure out what's wrong with my call to the .reload on the iframe, or tell me another way to refresh both pages at the same time?

Thanks for reading this post.

05-20-2011, 05:05 PM
I'd say skip:


and any variation on that. That sort of thing can vary by browser, and when two domains are involved, might be blocked anyway. I'm not even sure you can reload the page in the iframe that way even if it fetched the contentDocument. Windows and frames can reload, not documents. Try instead modifying the line above that to:

divTabFrame.innerHTML = '<iframe src="' + tab[1] + '?bustcache=' + (new Date().getTime()) + '" id="iframe' + ID + '" class="tabFrame"></iframe>';

That assumes the src attribute being passed (tab[1]) doesn't already have a query string. If it does, you would change ? to &. If it does sometimes and other times not, slightly more code would be required to determine when to use ? and when to use &.

That should force the server to fetch it anew each time.

Alternatively, if you had a name attribute (not id, which you can keep but not use for the below) for the iframe, you might be able to do a:


Or even without a name attribute, if it's the only iframe on the page:


If it's not the first iframe on the page, you can use its 0 based index. Like if it's the second iframe, use 1, third, use 2, and so on.

But the first method (adding the bustcache parameter) is better if it works, as it's less work for the server and the script.