Simple javascript question.

I’ve created a new window with this function –

Function1(){
var Win1 =Window.open(“http://myURL/printform.htm","PrintFormWindow”);
}

I want another function to write to that window. I thought something like this would work. -

Function2(){
window.name(‘PrintFormWindow’).document.writeln(‘test’);
}

But I get the error - ‘Object does not support this action’

Could I get some syntax help please?

Thanks

When are you getting that error? Is the new window opening at all? (i’d think the syntax of “Window.open” would be “window.open”…?)

When are you calling function2?

Try this syntax:

PrintFormWindow.document.writeln(‘test’);

Also if you’re not doing so already, test your page in Mozilla Firefox. It’s got a great Javascript console that actually gives you clues to what the problem is and where the offending line is located unlike IE which likes to be vague.

(Your right of course. window.open… it was a typo in the thread, not my code)

I get the error on the line of code -

window.name(‘PrintFormWindow’).document.writeln(‘test’);

PrintFormWindow opens fine with the code from function1()

The code -

PrintFormWindow.document.writeln(‘test’);

Produces the error ‘PrintFormWindow is undefined.’

function1() is called from a frames page. I think I may need an opener or parent statement in there or something.

Mozila doesn’t even allow me to spawn the first window. Popup blocker.

IE lets me spawn it even with Popup blocker on. IE will not let me spawn a second window from the first. It gets blocked. My solution was to write the info I need to the first window spawned with writeln.

try this:

declare var child in your main document javascript code, outside of any functions. (Probably not necessary, but always good to declare your variables. :wink: )

add
child = Win1
to function 1. (You don’t need to reference opener unless you have javascript running inside the PrintFormWindow)

then have function2 refer to child.document instead of windowwhatever.document

:slight_smile:

By the way, you do realize that once the document in printFormWindow has finished loading, any attempt to write to it again will overwrite what you already have?? (IIRC) To keep whatever is there and add extra text to that window, you’ll need to used DHTML or some other fancy tricks.

Ye ha,

Looks like that did it.

Very strange. Calling a function that opens a new window worked fine.

That new window had a form in it that called another function to open a second window. That second window always got blocked.

I do know that window1 will get overwriten, that’s what I want.

Thanks again, and I may be back. :wink: