473,513 Members | 3,777 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Comments and scripts

If I understand the specification corrently, comments are delimitted
by -- and --, but these delimitters can only occur in a block marked
by <! and >. Is this correct?

If I try to validate something like <!-- a -- b -- c --> then the
validator obviously complains about b: "invalid comment declaration:
found name start character outside comment but inside comment
declaration". Is there anything that can occur in such a place in
HTML? I wondered about the DOCTYPE statement, but it failed to
validate.

It's common to 'comment out' Javascript, but presumably in the
following:

<script type="text/javascript">
<!-- begin comment out
a=5;b=5;
b--;
if (a>b) document.write("<p>a is greater than b</p>");
// end comment out -->
</script>

the comment ends at the -- in 'b--;', the block containing the comment
ends at the '>' in 'if (a>b)', and the script elements ends at the
'</' in the '</p>'. If this occured in the document body, we would
see:

p>"; // end comment out -->

Am I correct in this assessment? (I know that real browsers cope with
horrible mess like this, I'm talking from a more theoretical
viewpoint.)

(I'm asking this as I'm thinking about automated HTML neatening -
presumably the correct approach is to removing the commenting out (as
pretty much all browsers now know not to display the contents of a
script element), parse the javascript, albeit at a very shallow level,
and escape occurances of </. Either that or move the javascript to an
external file, of course.)

--
Safalra (Stephen Morley)
http://www.safalra.com/hypertext/
Jul 20 '05 #1
1 2496
/Safalra/:
It's common to 'comment out' Javascript, but presumably in the
following:

<script type="text/javascript">
<!-- begin comment out
a=5;b=5;
b--;
if (a>b) document.write("<p>a is greater than b</p>");
// end comment out -->
</script>


Put your SCRIPT elements in the HEAD (and don't use comments) or
link the code externally (<script src="..." ...).

Browsers usually overcome the "<!--...--...-->" situation accepting
only "<!--" and "-->" for start and end delimiters of comments.

For SCRIPT elements which you need in the document body you could
presume UAs know how to handle them (no matter if they support
scripting or not), just narrow down the script code to a single
function call linking to code defined already in the HEAD or
possibly in an external file, so the mess would be minimal if one is
using a browser which doesn't know how to handle SCRIPT elements and
would render their content.

Note also the incompatibility of this technique of hidding SCRIPT
element's content with XHTML <http://www.w3.org/TR/xhtml1/#C_4>.

--
Stanimir
Jul 20 '05 #2

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

Similar topics

4
3367
by: Sims | last post by:
Hi, I proud myself in having good comments, (/**/, // etc...), all over my scripts as well as a very descriptive section at the beginning of the script. No correct me if i am wrong but php must still 'read' those comments? So, do comments technically slow the whole process? Or is the loss of CPU/Time/memory so negligible that i do not...
17
2729
by: lkrubner | last post by:
I've got a PHP application that's 2 megs in size. Of that, my guess is 200k-400k is comments. Do they impose a performance hit? I've been postponing any kind of optimization, but at some point I'll have to do it. Is taking out the comments worth it? Of all the optimizations I can do, where should it rank?
14
6091
by: dmh2000 | last post by:
I recently complained elsewhere that Python doesn't have multiline comments. i was told to use triple quoted strings to make multiline comments. My question is that since a triple quoted string is actually a language construct, does it use cause a runtime construction of a string which is then discarded, or is the runtime smart enough to see...
2
1191
by: Vivek Kumar | last post by:
Hi all, I have to write a network server (sort of) and I am looking for your valuable comments. Currently I have written a prototype in VB6 but it can only handle up to 30 or so clients. I need to upgrade the application so that it can handle up to 1000-1500 clients at a time (later if every thing works fine then hoping for 5000-6000...
0
1011
by: Paul M | last post by:
Hello, I need to examine the contents of a macro (ie the step it executes and their comments). I can look in the scripts (macros) collection but can't see the macros actions & comments (and any parameters) only top level properties. EG A macro called mcrTest has 2 actions:
5
1285
by: Carl J. Van Arsdall | last post by:
Hey everyone, another question for the list. In particular i'm looking for comments on some of the distributed technologies supported in python. Specifically, I'm looking at XML-RPC, RPyC, CORBA, and Twisted. Before you offer any comments let me talk about what i'm doing a little bit. Right now I'm creating an execution framework. The...
100
5026
by: jacob navia | last post by:
Recently, a heated debate started because of poor mr heathfield was unable to compile a program with // comments. Here is a utility for him, so that he can (at last) compile my programs :-) More seriously, this code takes 560 bytes. Amazing isn't it? C is very ompact, you can do great things in a few bytes. Obviously I have avoided...
3
3707
by: The Bicycling Guitarist | last post by:
Hello. I have many songs and essays pages that have been online more than ten years in some cases. These pages use HTML and CSS. Is there some way to allow visitors to add comments to these pages, the way most blogs allow comments by visitors? Of course I want the capability of deleting spam. Would migrating to a content management system do...
2
3561
hsriat
by: hsriat | last post by:
I am not sure how many of you would have faced this problem, but I faced this many times. I am not good at memorizing things, so I give lot of code comment in my code. And never wanted that code to reach the client. So I used to remove comments from each file by a PHP code and then upload that minified file to the server. Then an idea came...
0
7178
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7397
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7563
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7543
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5703
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
3252
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3239
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1612
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
813
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.