" " is not defined

E

Evan Sussman

Could any one give me an explenation of this error? I get it every
once in a while, and it really is a pain. currently the code that I'm
working with goes like this

<script>
<!--
var newwindow;
function moviepopup(url)
{

newwindow=window.open(url,'moviewindow','height=280,width=340,toolbar=no,menubar=no,locatio=no,status=yes,left=435,top=25');
if (window.focus) {newwindow.focus()}
}

function checkwindow()
{
if (!moviewindow.closed && moviewindow.location) {
moviepopup(url);
}
else
{
return false;
}
}
-->
</script>

that goes in the <HEAD>
and then it is called multiple times from the body like this

<div align="center"><font face="Verdana, Arial, Helvetica,
sans-serif" size="1"><font color="#993333"><strong>Sundance
/ Cabin</strong><br>
<a onClick="checkwindow()"
target="moviewindow"
href="javascript:moviepopup('movies/05-01.mov');"><img
src="images/movies/05-01.gif" alt="" name="" width="100" height="100"
border="0"></a></font> </font><br>
<font color="#993333" size="1"
face="Verdana, Arial, Helvetica, sans-serif">Click to Play</font><br>
<font face="Verdana, Arial, Helvetica,
sans-serif" size="1"><font face="Verdana, Arial, Helvetica, sans-serif"
size="1"><font color="#993333"> </font></font></font></div>

Now, if you can't tell what the effect I'm going for, its like this.
When you click on a picture, a sized windows appears with a movie
inside it. it loads and plays. If/When another movie is clicked on the
original page, I want the second movie to reload in the "moviewindow" I
was advised to write checkwindow() by a javascrpt guru through the
email, but it is hard to keep a conversation with him. can anyone help
me with this. thanks

-Evan
 
E

Evertjan.

Evan Sussman wrote on 26 sep 2005 in comp.lang.javascript:
Could any one give me an explenation of this error? I get it every
once in a while, and it really is a pain. currently the code that I'm
working with goes like this

<script>

missing type='text/javascript'

don't use this anymore since 2000
var newwindow;
function moviepopup(url)
{

newwindow=window.open(url,'moviewindow','height=280,width=340,toolbar=n
o,menubar=no,locatio=no,status=yes,left=435,top=25');
if (window.focus) {newwindow.focus()}

perhaps sometimes the newwindow is not ready when applying the focus.
why should window not have the focus, as you just clicked in it?

I suppose the code should be [and be testing for that]:

if (newwindow) {newwindow.focus()}

}

function checkwindow()
{
if (!moviewindow.closed && moviewindow.location) {
moviepopup(url);

Here add:

return true

else not realy necessary
{
return false;
}
}
-->

as above
</script>

that goes in the <HEAD>
and then it is called multiple times from the body like this

<div align="center"><font face="Verdana, Arial, Helvetica,
sans-serif" size="1"><font color="#993333"><strong>Sundance
/ Cabin</strong><br>

Please do not show us unnecessary code, it distracts.
<a onClick="checkwindow()"
target="moviewindow"

This target declaration is never used by your javascript, skip it.
href="javascript:moviepopup('movies/05-01.mov');">


The onclick needs a return:

onClick="return checkwindow()"

but I would prefer not to use the href="javascript:.. at all, try:

<a onClick="if (checkwindow())moviepopup('movies/05-01.mov');"
href='#'>

Or still better, move the moviepopup() into the checkwindow() function

<img
src="images/movies/05-01.gif" alt="" name="" width="100" height="100"
border="0"></a></font> </font><br>
<font color="#993333" size="1"
face="Verdana, Arial, Helvetica, sans-serif">Click to Play</font><br>
<font face="Verdana, Arial, Helvetica,
sans-serif" size="1"><font face="Verdana, Arial, Helvetica,
sans-serif" size="1"><font color="#993333">
</font></font></font></div>

skip most of this showing it to us.


Go from here
 
E

Evan Sussman

ok, when I changed
<a onClick="checkwindow()" target="moviewindow"
href="javascript:moviepopup('movies/05-01.mov');">
to

<a onClick="if (checkwindow())moviepopup('movies/05-01.mov');" >href="javascript:moviepopup('movies/05-01.mov');">

It worked, but it still returned "moviewindow is not defined" on line
31

then I tried it with

and it wouldn't load, still returned "movie is not defined" on line 31

so somehow, the href to the javascript is still needing to play a part
in the script. anyone have any suggestions. thanks Evertjan, as your
last post was very helpful.

-Evan
 
E

Evan Sussman

when I remove the href altogether, it still gives the same error as the
href="#" I guess that was a stupid attempt.
lol

-evan
still testing
 
A

Andy Jeffries

Evan said:
ok, when I changed




It worked, but it still returned "moviewindow is not defined" on line
31

And it isn't!

You assign window.open's result to newwindow and have newwindow as a
global variable. You should therefore use:


if (!newwindow.closed && newwindow.location) {
moviepopup(url);
}

There is probably another way to get to the moviewindow object (as you
assigned it that name), but not the way you're doing it.

Cheers,


Andy
 
E

Evan Sussman

now, after trying what you said Andy, it reloads the original window,
and gives the error "newwindow has no propertys" at line 31
 
A

Andy Jeffries

Evan said:
now, after trying what you said Andy, it reloads the original window,
and gives the error "newwindow has no propertys" at line 31

Is the page available online anywhere?

Anyway, try changing it to:

if (newwindow && !newwindow.closed && newwindow.location) {
moviepopup(url);
}

This should check to see if newwindow is set.

Cheers,


Andy
 
L

Lee

Evan Sussman said:
Could any one give me an explenation of this error? I get it every
once in a while, and it really is a pain. currently the code that I'm
working with goes like this

<script>
<!--
var newwindow;
function moviepopup(url)
{

newwindow=window.open(url,'moviewindow','height=280,width=340,toolbar=no,menubar=no,locatio=no,status=yes,left=435,top=25');
if (window.focus) {newwindow.focus()}
}

function checkwindow()
{
if (!moviewindow.closed && moviewindow.location) {


The first time you run checkwindow(), the window will not exist, and
so moviewindow will not be defined. The function should also check
to see if the window identifier is defined. You should actually be
using "newwindow", in place of "moviewindow", as the identifier.
 
E

Evan Sussman

after changing that, all it does is reload this time no errors. I guess
we're making progress, well now we can't target an error. Now we gotta
get the window to open, and the original window not to reload.
 
E

Evan Sussman

just realized I had a typo in the properties area, no change though.
also, the reason that the page is reloading, is that Firefox must
handle the href="#" as link to self. when I load the page in Safari,
there is no link and nothing happens when I click on the picture.
 
A

Andy Jeffries

Evan said:
after changing that, all it does is reload this time no errors. I guess
we're making progress, well now we can't target an error. Now we gotta
get the window to open, and the original window not to reload.

Sorry, I think I didn't actually listen to what you wanted it to do.
And still without reading that (but now I seem to have a better
understanding), how about the following

var newwindow;
function moviepopup(url)
{
if (newwindow) {
newwindow.location = url;
}
else {
newwindow=window.open(url,'moviewindow','height=280,width=340,toolbar=no,menubar=no,locatio=no,status=yes,left=435,top=25');
}
if (newwindow) {newwindow.focus()}
}

function checkwindow()
{
moviepopup(url);
if (!newwindow) {
return false;
}
}

I don't actually think you need the checkwindow function. Try that and
see if it does what you think. If not send me an email with your
MSN/ICQ/Jabber details and I'll try to help you over IM.

Cheers,


Andy
 
E

Evan Sussman

right now I have to go take care of something, I will get back here as
soon as I am done, thansk for the help, and I will see about an IM, i
don't have one right now.

-evan
 
E

Evan Sussman

just tried changing
newwindow=window.open(url,'moviewindow','height=280,width=340,toolbar=no,menubar=no,locatio=no,status=yes,left=435,top=25');
to

moviewindow=window.open(url,'moviewindow','height=280,width=340,toolbar=no,menubar=no,locatio=no,status=yes,left=435,top=25');

and adding
var moviewindow; under
var newwindow;

I am still returned "movie window has no properties" at line 32, why,
when I give it properties here
moviewindow=window.open(url,'moviewindow','height=280,width=340,toolbar=no,menubar=no,locatio=no,status=yes,left=435,top=25');

do I have to give the
var moviewindow;

properties, if so how?

-Evan

thanks guys
 
E

Evertjan.

Evan Sussman wrote on 26 sep 2005 in comp.lang.javascript:
just tried changing


and adding


I am still returned "movie window has no properties" at line 32, why,

We don't know about line numbers
when I give it properties here


do I have to give the


properties, if so how?

In general, and I said so earlier, it takes time to make a new window,
so while the window is being set up, it is not defined in the propperties
sense. Defining the variable that wil be it's pointer, won't help you.


This will give an error:

document.title = 'Original'
w = window.open('','myWindow','')
w.document.title = 'theWindow'

but this will work:

document.title = 'Original'
w = window.open('','myWindow','')
setTimeout("w.document.title = 'theWindow'",1000)

IE6 tested
 
W

web.dev

Evan said:
yeah, go to http://www.whitmoreacademy.com/movies.php
you will have to login with
UN=admin
PW=chilcotin

Hello Evan,

This is what you currently have on your site:
<script type="text/javascript">
var newwindow;
var moviewindow;

You don't appear to be using the variable moviewindow anywhere.
function moviepopup(url)
{
if (newwindow)
{
newwindow.loacation=url;

location is misspelled.
}
else
{
newwindow=window.open(url,'moviewindow','height=280,width=340,toolbar=no,menubar=no,location=no,status=yes,left=435,top=25');
if (newwindow)
{
newwindow.focus()

It's always a good practice to include a semi-colon at the end of every
statement.

Don't forget to include a closing } for your function.
function checkwindow()
{
if (newwindow && !newwindow.closed && newwindow.location)
{
moviepopup(url);

You're using the variable url here, however, where is the value coming
from?
return true

Add semi-colon at the end.
}
else
{
return false;
}
}
</script>

This is what you have done for your anchor links:
<a onClick="checkwindow()" target="moviewindow" href="javascript:moviepopup('movies/canada/1.mov');"></a>

Personally, I would prefer you would do it this way instead, and it
degrades nicely:

<a href = "movies/canada/1.mov" target = "moviewindow" onClick =
"return checkwindow()">...</a>

In fact, you can combine both of your functions to produce this
instead:

<script type="text/javascript">
var newwindow = null;

function showMovie(url)
{
if (newwindow && !newwindow.closed)
{
newwindow.location = url;
newwindow.focus();

return false;
}
else
{
newwindow =
window.open(url,'moviewindow','height=280,width=340,toolbar=no,menubar=no,location=no,status=yes,left=435,top=25');

return false;
}

return true;
}
</script>

Then in your anchor tag all you need to is the following:

<a href = "movies/canada/1.mov" target = "moviewindow" onClick =
"return showMovie('movies/canada/1.mov')">...</a>

Hope this helps.
 
A

ASM

Evertjan. a écrit :
Evan Sussman wrote on 26 sep 2005 in comp.lang.javascript:

just tried changing
[...]

In general, and I said so earlier,
[...]

but this will work:

document.title = 'Original'
w = window.open('','myWindow','')
setTimeout("w.document.title = 'theWindow'",1000)


this would have too

document.title = 'Original'
w = window.open('','myWindow','')
w.onload = function() { w.document.title = 'theWindow'}
 
E

Evan Sussman

Thanks, this does help. It works. Now I gotta change all of them, and I
need to examine what your script is doinginstead, thanks again

_Evan
 
E

Evan Sussman

also, I was expecting the script to pull url here...

function checkwindow()
{
if (newwindow && !newwindow.closed && newwindow.location)
{
moviepopup(url);

from

<a onClick="checkwindow()" target="moviewindow" href="javascript:moviepopup('movies/canada/1.mov');"></a>
moviepopup('movies/canada/1.mov');"

there,

from your reaction to it, I would guess that doesn't work. Please
explain how it does work, cause from the tutorial that I got the script
from, it seemed like thats what they wanted me to do.

-Evan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,431
Messages
2,571,677
Members
48,796
Latest member
Greg L.

Latest Threads

Top