Connecting Tech Pros Worldwide Forums | Help | Site Map

runtime error ..not an object etc ??

Geoff Cox
Guest
 
Posts: n/a
#1: Jul 20 '05
Hello,

One person to date has received a runtime error message saying
"parent.frameleft.location is not an object" with the following code.
The code is used to select 2 frames at the same time...

Any ideas why please?

Geoff

<script language="JavaScript">
<!--
function Home4()
{
parent.f-left.location.href = "subject-left.htm";
parent.f-right.location.href = "info-right.htm";
}
// -->
</script>

above is called from another page by the line (by clicking on a
button)

<a href="javascript:parent.Home4();" onMouseOut="MM_swapImgRestore()"



Richard Cornford
Guest
 
Posts: n/a
#2: Jul 20 '05

re: runtime error ..not an object etc ??


"Geoff Cox" <geoff.cox@blueyonder.co.uk> wrote in message
news:n3qkrvgomns5qnmvssv6l99kujjrl0oe9f@4ax.com...[color=blue]
>One person to date has received a runtime error message saying[/color]

If the code that you posted is the code you are using (and if not why
did you post it?) then it is surprising that it works for anyone.
[color=blue]
>"parent.frameleft.location is not an object" ... .[/color]
<snip>

The identifier "frameleft" does not appear in the code that you posted
so this error message cannot refer to that code.
[color=blue]
><script language="JavaScript">[/color]

The language attribute has been deprecated in HTML 4 and the type
attribute is required for valid HTML 4:-

<script type="text/javascript">
[color=blue]
><!--[/color]

This "hide from older browsers" stuff is no longer required as the
browsers that were young when it was introduced are now so old
themselves as to have gone out of use.
[color=blue]
>function Home4()
>{
>parent.f-left.location.href = "subject-left.htm";
>parent.f-right.location.href = "info-right.htm";[/color]

In JavaScript the hyphen ( - ) is the subtraction operator so the above
lines of code are attempting to subtract the value of left.location.href
from the value of parent.f and assign a string to the (if it worked,
numeric (probably NaN)) result. That guarantees that both lines would
produce at least one error and more likely several (though execution
would stop at the first).

If you have used the IDs/names "f-left" and "f-right" for frames in a
frameset then the problem that you cannot use a hyphen in a JavaScript
identifier can be avoided using square bracket notation:-

<URL: http://www.jibbering.com/faq/#FAQ4_39 >

It would probably be best to use name attributes and access the frames
from the "frames" collection of the parent object (using bracket
notation) and assign the string values directly to the location property
rather than its href property.

parent.frames['f-left'].location = "subject-left.htm";

(Incidentally, I have often read recommendations against using hyphens
in file names over the Internet (underscore characters are recommended
alternatives) but I have no idea how significant that is as I have never
used a hyphen in a file name.)

There is always a chance that any given browser that the script
encounters may not implement all of the objects required by your script.
As a result it is usually a good idea to verify the existence of browser
features before using them (so that otherwise predictable errors are not
generated and to provide an opportunity for active fall-back/controlled
degredation). Exactly how that would be implemented most efficiently
depends on factors that are not obvious from your posted code, but might
be as simple as wrapping the two assignments to the locations in - if -
tests:-

if((typeof parent != 'undefined')&&(parent.frames)){
if((parent.frames['f-left'])&&(parent.frames['f-left'].location)){
parent.frames['f-left'].location = "subject-left.htm";
}
if((parent.frames['f-right'])&&(parent.frames['f-right'].location)){
parent.frames['f-right'].location = "subject-right.htm";
}
}
[color=blue]
>}
>// -->
></script>[/color]

<snip>[color=blue]
><a href="javascript:parent.Home4();"[/color]

javascript pseudo-protocol HREFs are a bad idea. Instead the onclick
event handling attribute should be used (returning false to cancel the
navigation in the HREF) along with a real HREF for the users with
JavaScript disabled/unavailable.

<URL: http://www.jibbering.com/faq/#FAQ4_24 >
[color=blue]
>onMouseOut="MM_swapImgRestore()"[/color]

The Macromedia generated JavaScript functions are some of the worst
JavaScript ever written. You don't have to learn much to implement
alternatives an order of magnitude better yourself (especially if you
never take a Macromedia function as an example of anything except what
to avoid).

Richard.


Geoff Cox
Guest
 
Posts: n/a
#3: Jul 20 '05

re: runtime error ..not an object etc ??


On Wed, 19 Nov 2003 07:04:12 -0000, "Richard Cornford"
<Richard@litotes.demon.co.uk> wrote:
[color=blue]
>"Geoff Cox" <geoff.cox@blueyonder.co.uk> wrote in message
>news:n3qkrvgomns5qnmvssv6l99kujjrl0oe9f@4ax.com.. .[color=green]
>>One person to date has received a runtime error message saying[/color]
>
>If the code that you posted is the code you are using (and if not why
>did you post it?) then it is surprising that it works for anyone.[/color]

Richard,

apologies - my mistake - it should have read

<script language="JavaScript">
<!--
function Home4()
{
parent.frameleft.location.href = "subject-left.htm";
parent.frameright.location.href = "info-right.htm";
}
// -->
</script>

will read your answer now ...

Thanks

Geoff
[color=blue]
>[color=green]
>>"parent.frameleft.location is not an object" ... .[/color]
><snip>
>
>The identifier "frameleft" does not appear in the code that you posted
>so this error message cannot refer to that code.
>[color=green]
>><script language="JavaScript">[/color]
>
>The language attribute has been deprecated in HTML 4 and the type
>attribute is required for valid HTML 4:-
>
><script type="text/javascript">
>[color=green]
>><!--[/color]
>
>This "hide from older browsers" stuff is no longer required as the
>browsers that were young when it was introduced are now so old
>themselves as to have gone out of use.
>[color=green]
>>function Home4()
>>{
>>parent.f-left.location.href = "subject-left.htm";
>>parent.f-right.location.href = "info-right.htm";[/color]
>
>In JavaScript the hyphen ( - ) is the subtraction operator so the above
>lines of code are attempting to subtract the value of left.location.href
>from the value of parent.f and assign a string to the (if it worked,
>numeric (probably NaN)) result. That guarantees that both lines would
>produce at least one error and more likely several (though execution
>would stop at the first).
>
>If you have used the IDs/names "f-left" and "f-right" for frames in a
>frameset then the problem that you cannot use a hyphen in a JavaScript
>identifier can be avoided using square bracket notation:-
>
><URL: http://www.jibbering.com/faq/#FAQ4_39 >
>
>It would probably be best to use name attributes and access the frames
>from the "frames" collection of the parent object (using bracket
>notation) and assign the string values directly to the location property
>rather than its href property.
>
>parent.frames['f-left'].location = "subject-left.htm";
>
>(Incidentally, I have often read recommendations against using hyphens
>in file names over the Internet (underscore characters are recommended
>alternatives) but I have no idea how significant that is as I have never
>used a hyphen in a file name.)
>
>There is always a chance that any given browser that the script
>encounters may not implement all of the objects required by your script.
>As a result it is usually a good idea to verify the existence of browser
>features before using them (so that otherwise predictable errors are not
>generated and to provide an opportunity for active fall-back/controlled
>degredation). Exactly how that would be implemented most efficiently
>depends on factors that are not obvious from your posted code, but might
>be as simple as wrapping the two assignments to the locations in - if -
>tests:-
>
>if((typeof parent != 'undefined')&&(parent.frames)){
> if((parent.frames['f-left'])&&(parent.frames['f-left'].location)){
> parent.frames['f-left'].location = "subject-left.htm";
> }
> if((parent.frames['f-right'])&&(parent.frames['f-right'].location)){
> parent.frames['f-right'].location = "subject-right.htm";
> }
>}
>[color=green]
>>}
>>// -->
>></script>[/color]
>
><snip>[color=green]
>><a href="javascript:parent.Home4();"[/color]
>
>javascript pseudo-protocol HREFs are a bad idea. Instead the onclick
>event handling attribute should be used (returning false to cancel the
>navigation in the HREF) along with a real HREF for the users with
>JavaScript disabled/unavailable.
>
><URL: http://www.jibbering.com/faq/#FAQ4_24 >
>[color=green]
>>onMouseOut="MM_swapImgRestore()"[/color]
>
>The Macromedia generated JavaScript functions are some of the worst
>JavaScript ever written. You don't have to learn much to implement
>alternatives an order of magnitude better yourself (especially if you
>never take a Macromedia function as an example of anything except what
>to avoid).
>
>Richard.
>[/color]

Geoff Cox
Guest
 
Posts: n/a
#4: Jul 20 '05

re: runtime error ..not an object etc ??


On Wed, 19 Nov 2003 07:04:12 -0000, "Richard Cornford"
<Richard@litotes.demon.co.uk> wrote:

Richard,

if I have understood you correctly so far I have changed the code with
the select button to

<a href="withjs.htm" target = "_top" onclick="parent.Home4();return
false" etc

In fact at the moment because of the runtime error I have fallen back
to using no javascript and using a different frameset for each
combination of 2 pages ...

It seems that I can use the above javascript code as if javascript is
not enabled the withjs.htm uses the frameset only approach.

Can you see any errors/problems?!

Thanks

Geoff

[color=blue]
>"Geoff Cox" <geoff.cox@blueyonder.co.uk> wrote in message
>news:n3qkrvgomns5qnmvssv6l99kujjrl0oe9f@4ax.com.. .[color=green]
>>One person to date has received a runtime error message saying[/color]
>
>If the code that you posted is the code you are using (and if not why
>did you post it?) then it is surprising that it works for anyone.
>[color=green]
>>"parent.frameleft.location is not an object" ... .[/color]
><snip>
>
>The identifier "frameleft" does not appear in the code that you posted
>so this error message cannot refer to that code.
>[color=green]
>><script language="JavaScript">[/color]
>
>The language attribute has been deprecated in HTML 4 and the type
>attribute is required for valid HTML 4:-
>
><script type="text/javascript">
>[color=green]
>><!--[/color]
>
>This "hide from older browsers" stuff is no longer required as the
>browsers that were young when it was introduced are now so old
>themselves as to have gone out of use.
>[color=green]
>>function Home4()
>>{
>>parent.f-left.location.href = "subject-left.htm";
>>parent.f-right.location.href = "info-right.htm";[/color]
>
>In JavaScript the hyphen ( - ) is the subtraction operator so the above
>lines of code are attempting to subtract the value of left.location.href
>from the value of parent.f and assign a string to the (if it worked,
>numeric (probably NaN)) result. That guarantees that both lines would
>produce at least one error and more likely several (though execution
>would stop at the first).
>
>If you have used the IDs/names "f-left" and "f-right" for frames in a
>frameset then the problem that you cannot use a hyphen in a JavaScript
>identifier can be avoided using square bracket notation:-
>
><URL: http://www.jibbering.com/faq/#FAQ4_39 >
>
>It would probably be best to use name attributes and access the frames
>from the "frames" collection of the parent object (using bracket
>notation) and assign the string values directly to the location property
>rather than its href property.
>
>parent.frames['f-left'].location = "subject-left.htm";
>
>(Incidentally, I have often read recommendations against using hyphens
>in file names over the Internet (underscore characters are recommended
>alternatives) but I have no idea how significant that is as I have never
>used a hyphen in a file name.)
>
>There is always a chance that any given browser that the script
>encounters may not implement all of the objects required by your script.
>As a result it is usually a good idea to verify the existence of browser
>features before using them (so that otherwise predictable errors are not
>generated and to provide an opportunity for active fall-back/controlled
>degredation). Exactly how that would be implemented most efficiently
>depends on factors that are not obvious from your posted code, but might
>be as simple as wrapping the two assignments to the locations in - if -
>tests:-
>
>if((typeof parent != 'undefined')&&(parent.frames)){
> if((parent.frames['f-left'])&&(parent.frames['f-left'].location)){
> parent.frames['f-left'].location = "subject-left.htm";
> }
> if((parent.frames['f-right'])&&(parent.frames['f-right'].location)){
> parent.frames['f-right'].location = "subject-right.htm";
> }
>}
>[color=green]
>>}
>>// -->
>></script>[/color]
>
><snip>[color=green]
>><a href="javascript:parent.Home4();"[/color]
>
>javascript pseudo-protocol HREFs are a bad idea. Instead the onclick
>event handling attribute should be used (returning false to cancel the
>navigation in the HREF) along with a real HREF for the users with
>JavaScript disabled/unavailable.
>
><URL: http://www.jibbering.com/faq/#FAQ4_24 >
>[color=green]
>>onMouseOut="MM_swapImgRestore()"[/color]
>
>The Macromedia generated JavaScript functions are some of the worst
>JavaScript ever written. You don't have to learn much to implement
>alternatives an order of magnitude better yourself (especially if you
>never take a Macromedia function as an example of anything except what
>to avoid).
>
>Richard.
>[/color]

Dr John Stockton
Guest
 
Posts: n/a
#5: Jul 20 '05

re: runtime error ..not an object etc ??


JRS: In article <bpf4lb$k6f$1$830fa78d@news.demon.co.uk>, seen in
news:comp.lang.javascript, Richard Cornford
<Richard@litotes.demon.co.uk> posted at Wed, 19 Nov 2003 07:04:12 :-[color=blue]
>
>(Incidentally, I have often read recommendations against using hyphens
>in file names over the Internet (underscore characters are recommended
>alternatives) but I have no idea how significant that is as I have never
>used a hyphen in a file name.)
>[/color]

All my javascript page names have them, and more than half of the total
*.htm in the master root directory. No complaints, IIRC.

One reason for avoiding them could be that nasty MS software used also
for WP may use em- or en-dash instead. The remedy is clear.

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://jibbering.com/faq/> Jim Ley's FAQ for news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> JS maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/JS/&c., FAQ topics, links.
Closed Thread