/    Sign up×
Community /Pin to ProfileBookmark

iframe document.write problem

I’m trying to use document.write() to write to an iframe.document object and then access the iframe.document.body object, but it seems to be always null. I could really use some tips:

function writeContentToParamsFrame(url) {
//retrieves document content from the server using an XMLHTTPRequest object
var response = getRemoteDocumentContent(url);

//do some regex manipulation of the response
//yada yada yada

//replace the content of the iframe:
var idoc = window.frames[‘paramsframe’].document;
idoc.open();
idoc.write(response);
//override the background color from the response:
idoc.body.style.backgroundColor = getContainerBackgroundColor();
idoc.close();
}

//….. snip

<div id=”lower1content”>
<iframe id=”paramsframe” name=”paramsframe” src=”empty.htm”></iframe>
</div>

//…. snip

In IE 6.0, this works fine, but on Firefox, the idoc
The problem is that the idoc.body.style.backgroundColor fails. idoc.body is undefined. looking more into this:

idoc.GetElementsByName(“body”) returns a zero length array, so apparently, “body” does not exist?

Thanks for any help.

Steve

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@konithomimoMay 23.2006 — FOr iframes you sometimes have to do things differently than with regular windows. Instead of doing document.body.style try contentWindow.document.body.style or content.document.body.style

The first one should work though.
×

Success!

Help @mazer1310 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.25,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...