/    Sign up×
Community /Pin to ProfileBookmark

clarification on document.write called in function

In a frameset, the first frame is calling a function in the second, but this is a document.write. Can’t find info on this, but apparently the document.write function only works once? What I’d like to do is, depending on the onclick used, write the new content in the second frame (yeah, I could just change the href, but now I’m curious about this). Test code as follows:

this is in frame one:
<TR>
<TH ID=”question_1″ ONCLICK=”(parent.hints.writehint_1() )”>
Do you want hint #1
</TH>
</TR>

<TR>
<TH ID=”question_1″ ONCLICK=”(parent.hints.writehint_2() )”>
Do you want hint #2
</TH> ……….etc……………

and these are the functions in frame two:

<SCRIPT>

function writehint_1()
{
document.write(“<html><head></head><Body><TABLE WIDTH=100% BORDER=0><TR><TD>This is function call 1 from another frame.</TD></TR></TABLE></body></html>”);
document.close();

};

function writehint_2()
{
document.write(“<html><head></head><Body><TABLE WIDTH=100% BORDER=0><TR><TD>This is function call 2 from another frame.</TD></TR></TABLE></body></html>”);
document.close();

};

</SCRIPT>

..etc……end of code

Thanks for any info.

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@Khalid_AliJun 06.2005 — document.write can run multiple times but what it will do is re-write the whole document, hence making everyting that you had there out of scope.

what you want to do is use element.innerHTML="<html stuff> here</html stuff>";

this will work in the manner you want it to.
×

Success!

Help @kirthe 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.3,
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: @Yussuf4331,
tipped: article
amount: 1000 SATS,

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

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...