473,396 Members | 1,961 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Trying to understand this code

Here is the code I found:

<script language="JavaScript">
<!--
if (parent.frames.length > 0)
{
parent.location.href = location.href;
}
-->
</script>

What it looks like I'm seeing is a function that will automatically
break the page out of any frameset it finds itself in. Am I right?

Chad Lupkes
ch********@yahoo.com
Jul 20 '05 #1
9 1883
ch********@yahoo.com (Chad Lupkes) writes:
Here is the code I found:

<script language="JavaScript">
It's
<script type="text/javascript">
In HTML 4, the type attrbute is required.
<!--
HTML comments are useless in Javascript.
if (parent.frames.length > 0)
{
parent.location.href = location.href;
} What it looks like I'm seeing is a function that will automatically
break the page out of any frameset it finds itself in. Am I right?


This code testes whether the parent window/frames has more than one
frame inside it. If it does, this page is loaded into the parent.

It will not break out of a parent frame with only one subframe. That
is quite possible, if the parent includes this page in an iframe.

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #2

"Lasse Reichstein Nielsen" <lr*@hotpop.com> wrote in message
news:u1**********@hotpop.com...
ch********@yahoo.com (Chad Lupkes) writes:
Here is the code I found:

<script language="JavaScript">
It's
<script type="text/javascript">
In HTML 4, the type attrbute is required.
<!--


HTML comments are useless in Javascript.


Don't be such a prick, maybe he's trying to code for, or keep in practice
for backward compatability with older browsers, or non-javascript enabled
browsers. Don't act like you don't know what that comment mark is for.

Tony Vasquez
if (parent.frames.length > 0)
{
parent.location.href = location.href;
}

What it looks like I'm seeing is a function that will automatically
break the page out of any frameset it finds itself in. Am I right?


This code testes whether the parent window/frames has more than one
frame inside it. If it does, this page is loaded into the parent.

It will not break out of a parent frame with only one subframe. That
is quite possible, if the parent includes this page in an iframe.

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit.html>
'Faith without judgement merely degrades the spirit divine.'

Jul 20 '05 #3
DU
Tony Vasquez wrote:


Don't be such a prick, maybe he's trying to code for, or keep in practice
for backward compatability with older browsers, or non-javascript enabled
browsers. Don't act like you don't know what that comment mark is for.

Tony Vasquez


It's amazing how fast people resort to abrasive remarks, name-calling or
just plain agressive posts when a simple question done in a neutral
manner was appropriate and would have done a whole difference.

DU
--
Javascript and Browser bugs:
http://www10.brinkster.com/doctorunclear/
- Resources, help and tips for Netscape 7.x users and Composer
- Interactive demos on Popup windows, music (audio/midi) in Netscape 7.x
http://www10.brinkster.com/doctorunc...e7Section.html

Jul 20 '05 #4
"Tony Vasquez" <co**********@earthlink.net> writes:
HTML comments are useless in Javascript.


Don't be such a prick, maybe he's trying to code for, or keep in practice
for backward compatability with older browsers, or non-javascript enabled
browsers. Don't act like you don't know what that comment mark is for.


I can see I should have kept my usual wording, and not replaced
"unneeded" with "useless".

Still, it doesn't change that it is correct.

The tradition of adding HTML comments was introduced with the first
browser to understand the script tag, Netscape 2, to hide the scripts
from Netscape 1 and other contemporal browsers.

The browsers that need HTML comments to hide the contents of a script
tag, are browsers that don't understand the script tag at all. The tag
was included in HTML 3.2, which was made a recommendation in January
1997, and was in use in browsers even before.

The most recents such browser not understanding the scrip tag, that I
am aware off, are Netscape 1, Internet Explorer 2, Lynx 2.4, and Opera
2. These were succeeded by more modern browsers around 1996 (Opera not
until 1997).

Any slightly recent browser that doesn't support Javascript (like Lynx
2.5 from May 1996) still understands the script tag, probably as part
of HTML 3.2, and knows not to render its content.

I know exactly what the HTML comment is for, and it is not needed for
browsers created after 1996. If you can find just *one* version of IE2
or NS1 in actualy use (and not just by weirdos like me who collects
browsers), then I would accept that HTML comments in Javascript tags
have a use.

Until then, I stand by my opinion: HTML tags are of no use in
Javascript.

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #5
Lasse Reichstein Nielsen wrote on 07 sep 2003 in comp.lang.javascript:
Until then, I stand by my opinion: HTML tags are of no use in
Javascript.


Hear, hear !

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jul 20 '05 #6
JRS: In article <4q**********@hotpop.com>, seen in
news:comp.lang.javascript, Lasse Reichstein Nielsen <lr*@hotpop.com>
posted at Sun, 7 Sep 2003 12:56:25 :-
> HTML comments are useless in Javascript.
I can see I should have kept my usual wording, and not replaced
"unneeded" with "useless".

Still, it doesn't change that it is correct.


Actually it is not quite correct.

It is, I think, true to say that no recent Web browser needs those
comments, and perhaps also that the number of older browsers still in
use is negligible (remember the possibility of old systems in third-
world locations, however).

It may well be equally true to say the same about Javascript executed in
Web servers, and elsewhere.

It may well be true to say the same about all currently-available Web-
page validators, with a similar caveat about old versions of
downloadable ones.

But there is at least one publicly-available tool which reads Web page
masters and which under at least some circumstances benefits from the
presence of <!-- and --> around script.

There is a somewhat analogous situation with Web page masters containing
VBscript. VBScript comment by definition is introduced by ', equivalent
to javascript // - however, my latest copy of W3's TIDY does not like
this, but is happy with '' - IIRC.

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 MIME. ©
Web <URL:http://www.merlyn.demon.co.uk/> - FAQqish topics, acronyms & links.
PAS EXE TXT ZIP via <URL:http://www.merlyn.demon.co.uk/programs/00index.htm>.
Do not Mail News to me. Before a reply, quote with ">" or "> " (SoRFC1036)
Jul 20 '05 #7
On Sun, 7 Sep 2003 20:01:56 +0100, Dr John Stockton
<sp**@merlyn.demon.co.uk> wrote:
It is, I think, true to say that no recent Web browser needs those
comments, and perhaps also that the number of older browsers still in
use is negligible (remember the possibility of old systems in third-
world locations, however).
In the 3rd world those browsers are even less likely to be used as at
least one of them didn't know HTTP 1.1 and outside the 1st English
speaking world, there's an even larger proportion of virtual hosts
than non (since they don't have as many IP addresses as the "west")
But there is at least one publicly-available tool which reads Web page
masters and which under at least some circumstances benefits from the
presence of <!-- and --> around script.


Yes, but seen as people are authoring XHTML, this will cause problems
since in XHTML such comments will mean that the script is _not
executed_ So on the balance of properties in the real world today,
I'd say going with the so-called future, is a better bet than the
remote past on browsers which are unusable on the web today.

Jim.
--
comp.lang.javascript FAQ - http://jibbering.com/faq/

Jul 20 '05 #8
Dr John Stockton <sp**@merlyn.demon.co.uk> writes:
But there is at least one publicly-available tool which reads Web page
masters and which under at least some circumstances benefits from the
presence of <!-- and --> around script.


Don't leave us hanging in suspense! What is it? :)

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #9
JRS: In article <vf**********@hotpop.com>, seen in
news:comp.lang.javascript, Lasse Reichstein Nielsen <lr*@hotpop.com>
posted at Sun, 7 Sep 2003 22:14:28 :-
Dr John Stockton <sp**@merlyn.demon.co.uk> writes:
But there is at least one publicly-available tool which reads Web page
masters and which under at least some circumstances benefits from the
presence of <!-- and --> around script.


Don't leave us hanging in suspense! What is it? :)


A clue was in the third line of the signature (repeated).

CHEKLINK, running on a PC in 16- and 32- bit versions, will check the
relative links on [the master copy of] a Web site, recursively, to see
whether the file and/or anchor cited by each link actually exists in the
master. It checks a few other things /en passant/.

Since its high-speed scanner was written to ignore all bar a few HTML
elements, but naturally to recognise <!-- --> (acknowledged : perhaps
that is not the full generality of HTML comment; but it is all that I've
ever seen used), it is entirely ignorant of the contents of
traditionally-protected script (unless out of sheer folly a string
literal contains -->). But, without the protection, it may run out of
buffer length (and thus abort) while scanning script.

I think also that one version of W3's TIDY (HTML checker) could be led
astray by <a in unprotected script, where a is any letter and there is
no suitable matching > - I spent a while changing <a to < a to fix that,
after removing <!-- & -->.

But an advantage of removal is that CHEKLINX will then check the link in
document.write('<a href="filename.htm#anchor">GO</a>'). I do not know
how many of such I had that were satisfactory, but it did find one that
was not; the destination had moved.
Those show that the removal of the deprecated <!-- & --> is not
necessarily consequence-free.

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 MIME. ©
Web <URL:http://www.merlyn.demon.co.uk/> - FAQqish topics, acronyms & links.
PAS EXE TXT ZIP via <URL:http://www.merlyn.demon.co.uk/programs/00index.htm>.
Do not Mail News to me. Before a reply, quote with ">" or "> " (SoRFC1036)
Jul 20 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Leny | last post by:
Hi, I'd like to colaborate with an open source project that have been in development for the last four years. There is almost no documentation at all, and it's extremely hard even to get a...
9
by: | last post by:
void show( char *s, ...) is a function seemd like prinf code -------------- #include <stdio.h> #include <stdarg.h> void show( char *s, ...) { va_list stage;
4
by: rahul8143 | last post by:
hello, I am trying following code that help me to understand difference between what happens when value is assigned to pointer or reference but it has some errors how to remove that? #include...
0
by: Brian Hampson | last post by:
I'd like to be able to write an add-in that would rotate my display picture, through my set of display pics for MSN Messenger. I suppose I'm looking for an add-in API, and some pointers to how to...
14
by: Michael McCarthy | last post by:
This code is supposed to create a streamreader object from a stream object and I suppose use encoding if requested (enc isn't null)... The second bit is someone elses code... /// code block #1...
5
by: Antoine | last post by:
Hi I have a novice question. I am writing some code, and several routines in ..NET. So far very succesfully using several sample to work from, though am I jumping in by doing this and I really need...
3
by: skosmicki | last post by:
I need to create an function similar to the "MATCH" function in Excel that evaluates a number within a set of numbers and returns whether there is a match. I have put the example of what I see in...
10
by: vfunc | last post by:
OK, after reading some C++ books and writing some programs that cover the core, where do I go from there, to say be able to read some open source code ? How do you unravel other peoples code when...
1
by: fraggle10 | last post by:
Hi there I am trying to build a chat client in PHP and would appreciate any help please thanks again
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.