/    Sign up×
Community /Pin to ProfileBookmark

write on child windows?

firstWindow.htm
secondWindow.htm

When I click on firstWindow.htm, the secondWindow.htm will pop up. How can I write a code in a firstWindow, and the output will be secondWindow?

Example:
1stWindows
document.write(“test”);
2stWindows
–>will output “test”.

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@ricpApr 15.2007 — <i>
</i>var myPopup = window.open();
myPopup.document.write("test");


The myPopup variable is a reference to the 'window' object of the new window. In the reverse, you would use the 'opener' object in the popup to refer to it's "parent".

hope that helps.
Copy linkTweet thisAlerts:
@NaldzApr 15.2007 — <i>
</i>var myPopup = window.open();
myPopup.document.write("test");

[/QUOTE]


Its true that the myPopup variable is reference to the child window but doing the document.write on the child window will not work, since document.write only works during onload, but if it does work the, contents of the whole child window page will be replaced by the text that you have written through the document.write in the parent window. Since the problem was assigning values to the child window from the parent window will have to do that using the DOM way.

[CODE]
var popup = window.open();
popup.document.getElementById('elementFromChildWindow').value = 'value';//assuming that the element that is to be filled has an ID of 'elementFromChildWindow' this line should only be executed once the popup window has already been loaded.
[/CODE]
Copy linkTweet thisAlerts:
@ricpApr 15.2007 — Its true that the myPopup variable is reference to the child window but doing the document.write on the child window will not work, since document.write only works during onload .. [/QUOTE]

You are right, but from his original post that's what I actually thought he wanted.
×

Success!

Help @letdoit 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 6.16,
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: @nearjob,
tipped: article
amount: 1000 SATS,

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

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