Click to See Complete Forum and Search --> : window.open, mywindow.write...ERROR!!


cranepr
07-10-2003, 08:13 AM
I have been "learning" Javascript from the book
JAVASCRIPT by Kelly Murdock.

On pages 128 and 129 I am instructed to Open A New Browser Window using this sample code:

window.open("mypage.html", "mywindow", "width=200, height=400, toolbar=no, status=no, resizeable=yes");

This part works fine......HOWEVER....

on the next page it specifically states,
"From the original Web page, you can write text to the new window. When you create a new window, one of the parameters is to give the new window a name. This name can be used to send output to the new window...and mywindow.write() writes text to a new window named mywindow."

So for my next line of code I entered:

mywindow.write("Undefined????");

and, you guessed it, when I ran that in the browser I got the error message "mywindow is undefined."

I've been up all night rearranging it in a million different ways and still get that error message.
What I have learned about Javascript so far is that errors like this are usually due to some "obvious" little thing.

Can anybody tell me what I've overlooked?

freefall
07-10-2003, 08:50 AM
I'm pretty sure this is what you need to do:

<script type="text/javascript">
var mywindow = window.open("mypage.html", "mywindow", "width=200, height=400, toolbar=no, status=no, resizeable=yes");
mywindow.document.open();
mywindow.document.write("Undefined????");
mywindow.document.close();
</script>


- Ian

cranepr
07-10-2003, 09:05 AM
Thank you very much for both a quick reply and an accurate answer.

I just tried it and it works great.

I think I understand the concept, now that I see it.

I have to assign the name of the new window to the whole window.open statement...(even though the name is specified within the statement..??)...but anyway....long as it works.

And....it makes sense that even though I've opened a new window, I should also have to open the document before I can write in it, and close it when I'm done...just like the refrigerator, lol.
Funny, this book I have just glosses right over those kind of "little" details.

Any suggestions for a better book?

Thanks again!......now I can get some sleep.

freefall
07-10-2003, 09:10 AM
I'm glad you understand the reasoning behind it, most of the time it's just "okay, thanks *copy, paste, come back in 2 days with a new question*"

I've never used a book myself, I learned C++ in school and then applied that to javascript, which I learned by example.
http://www.w3schools.com/ has a good starting program in javascript, and if you ever need a reference, browse here:
http://msdn.microsoft.com/library/default.asp?url=/workshop/author/dhtml/reference/objects/div.asp

Good luck,
Ian