Re: [WSG] commenting javascript in script tags

2007-04-26 Thread David Hucklesby
On Thu, 26 Apr 2007 10:26:41 +1000, Andrew Harris wrote:
 'morning all,

 It is common and often recommended practice to comment javascript placed in a 
 document.

 script type=text/javascript language=javascript !-- myVariable = 
 'woo'; // --
 /script

Netscape 2 introduced JavaScript (Livescript) in 1995. Netscape 1 did not 
recognize the SCRIPT tags, and rendered the script on screen. Hence
the need, back then, for the HTML comments.

Only needed today if you wish to support Netscape 1.


 While I'm on the topic - what about the whole ![CDATA[ ... ]] thing? Should 
 I be
 using that? What are the possible consequences of ignoring it like the vast 
 majority of
 page authors?

CDATA sections are required for embedded code only for XHTML.
If your file names end in .htm, .html, .php etc. then every browser
in the world will treat your XHTML as poorly marked up HTML.

XHTML markup works because, unlike XHTML, HTML is required to be 
forgiving of minor errors and several omissions.

If you use a strict XHTML DOCTYPE, you can check out the
consequences of various markup options by saving a local copy
of your page with a .xhtml extension instead of .html. Opera and
Firefox on Windows, at least, will treat this as real XHTML.

Cordially,
David
--



***
List Guidelines: http://webstandardsgroup.org/mail/guidelines.cfm
Unsubscribe: http://webstandardsgroup.org/join/unsubscribe.cfm
Help: [EMAIL PROTECTED]
***



Re: [WSG] commenting javascript in script tags

2007-04-26 Thread Stuart Foulstone
Hi,

HTML is not required to be forgiving of minor errors and omissions.

It's the normal PC based browsers such as IE, Netscape and Mozilla that
developed alongside non-standards coding (and Dreamweaver) that had to be
forgiving of errors - not HTML per se.

A mobile lightweight browser that does not have the computing power to be
able detect and try to interpret bad code and hacks will fail to do this.

As the number of such devices increases so does the need for standards.  
That's the reason this forum exists - to design for the future, rather
than just what you can get away with in today's browsers.

Stuart





On Thu, April 26, 2007 7:08 am, David Hucklesby wrote:
 On Thu, 26 Apr 2007 10:26:41 +1000, Andrew Harris wrote:
 'morning all,

 It is common and often recommended practice to comment javascript placed
 in a document.

 script type=text/javascript language=javascript !-- myVariable =
 'woo'; // --
 /script

 Netscape 2 introduced JavaScript (Livescript) in 1995. Netscape 1 did not
 recognize the SCRIPT tags, and rendered the script on screen. Hence
 the need, back then, for the HTML comments.

 Only needed today if you wish to support Netscape 1.


 While I'm on the topic - what about the whole ![CDATA[ ... ]] thing?
 Should I be
 using that? What are the possible consequences of ignoring it like the
 vast majority of
 page authors?

 CDATA sections are required for embedded code only for XHTML.
 If your file names end in .htm, .html, .php etc. then every browser
 in the world will treat your XHTML as poorly marked up HTML.

 XHTML markup works because, unlike XHTML, HTML is required to be
 forgiving of minor errors and several omissions.

 Cordially,
 David
 --



 ***
 List Guidelines: http://webstandardsgroup.org/mail/guidelines.cfm
 Unsubscribe: http://webstandardsgroup.org/join/unsubscribe.cfm
 Help: [EMAIL PROTECTED]
 ***




-- 
Stuart Foulstone.
http://www.bigeasyweb.co.uk
BigEasy Web Design
69 Flockton Court
Rockingham Street
Sheffield
S1 4EB

Tel. 07751 413451


***
List Guidelines: http://webstandardsgroup.org/mail/guidelines.cfm
Unsubscribe: http://webstandardsgroup.org/join/unsubscribe.cfm
Help: [EMAIL PROTECTED]
***



Re: [WSG] commenting javascript in script tags

2007-04-26 Thread Stuart Foulstone
Hi,

Could you explain why the script snippet has to be in the head?

Will it have some some adverse effect on other pages if in a common
external file?  If so, why can't it be in an additional .js file, called
only by that page?

Stuart


On Thu, April 26, 2007 2:47 am, Andrew Harris wrote:
 On 4/26/07, Patrick H. Lauke [EMAIL PROTECTED] wrote:
 Use external scripts, and you avoid both issues quite elegantly.

 Thanks Patrick - I should point out that this question is mostly in
 regards to a case where the bulk of the js is an external script. I
 just need to occasionally insert a variable relevant to a particular
 page. So, abhorrent as it might be, the script snippet has to live in
 the head.

 --
 Andrew Harris
 [EMAIL PROTECTED]
 http://www.woowoowoo.com


 ***
 List Guidelines: http://webstandardsgroup.org/mail/guidelines.cfm
 Unsubscribe: http://webstandardsgroup.org/join/unsubscribe.cfm
 Help: [EMAIL PROTECTED]
 ***




-- 
Stuart Foulstone.
http://www.bigeasyweb.co.uk
BigEasy Web Design
69 Flockton Court
Rockingham Street
Sheffield
S1 4EB

Tel. 07751 413451


***
List Guidelines: http://webstandardsgroup.org/mail/guidelines.cfm
Unsubscribe: http://webstandardsgroup.org/join/unsubscribe.cfm
Help: [EMAIL PROTECTED]
***



Re: [WSG] commenting javascript in script tags

2007-04-26 Thread Breton Slivka


On 26/04/2007, at 5:19 PM, Andrew Harris wrote:


On 4/26/07, Stuart Foulstone [EMAIL PROTECTED] wrote:

Could you explain why the script snippet has to be in the head?

Will it have some some adverse effect on other pages if in a common
external file?  If so, why can't it be in an additional .js file,  
called

only by that page?


OK, of course, it doesn't HAVE to be in the head, but in this case,
it's much more convenient that way. I am rolling out a dreamweaver
template that will be used on many thousands of pages. They all
reference a central javascript, but occasionally a variable needs to
be customised for certain pages. The variable is pretty much unique to
the page, so while an external file could be created, it's pointless
for one line of code... especially when dealing with a large number of
users of varying skill levels - copy and paste code samples into an
editable area in the head is nice and easy :-)

--
Andrew Harris
[EMAIL PROTECTED]
http://www.woowoowoo.com






why not markup the variable as html and use dom scripting in the  
central script to pull out the variable from the individual pages?






***
List Guidelines: http://webstandardsgroup.org/mail/guidelines.cfm
Unsubscribe: http://webstandardsgroup.org/join/unsubscribe.cfm
Help: [EMAIL PROTECTED]
***



Re: [WSG] commenting javascript in script tags

2007-04-26 Thread Lachlan Hunt

Andrew Harris wrote:

It is common and often recommended practice to comment javascript
placed in a document.

script type=text/javascript language=javascript
   !--
   myVariable = 'woo';
   // --
/script


Don't bother using those comments, they're a waste of time.


The reason cited is that 'very old browsers' that do not understand
the script tag may print the raw code.

How old are we talking? Has anyone ever seen this happen? Can't we
safely leave behind what is essentially a hack?


Sadly, yes.  The browser embedded in a a particular mobile phone (I 
think it's the  Motorolla V3) does not recognise the script element and 
will render the script on screen if it's not commented out.  However, 
that phone and its browser have far more significant problems and is 
safe to ignore.


Other than that, any browser released since the mid-90's will recognise 
the script element and hide its content.



While I'm on the topic - what about the whole ![CDATA[ ... ]] thing?


No.  That is for use in XHTML only.  In HTML, the content of the script 
element is parsed differently from other markup.


See this article of mine for a more detailed explanation.

http://lachy.id.au/log/2005/05/script-comments

--
Lachlan Hunt
http://lachy.id.au/


***
List Guidelines: http://webstandardsgroup.org/mail/guidelines.cfm
Unsubscribe: http://webstandardsgroup.org/join/unsubscribe.cfm
Help: [EMAIL PROTECTED]
***



Re: [WSG] commenting javascript in script tags

2007-04-26 Thread Mordechai Peller

Michael MD wrote:

PC-based browsers are forgiving because that's what most users prefer.
I don't think most users know enough to even have a preference. The 
problem is that if many pages don't render properly, they are more 
likely to blame the browser that the sites. Strictly speaking, most 
pages shouldn't render properly. Most users have no clue of the sad 
state of our industry.



***
List Guidelines: http://webstandardsgroup.org/mail/guidelines.cfm
Unsubscribe: http://webstandardsgroup.org/join/unsubscribe.cfm
Help: [EMAIL PROTECTED]
***



Re: [WSG] commenting javascript in script tags

2007-04-25 Thread Patrick H. Lauke

Andrew Harris wrote:

'morning all,

It is common and often recommended practice to comment javascript
placed in a document.

...

While I'm on the topic - what about the whole ![CDATA[ ... ]] thing?


Use external scripts, and you avoid both issues quite elegantly.

P
--
Patrick H. Lauke
__
re·dux (adj.): brought back; returned. used postpositively
[latin : re-, re- + dux, leader; see duke.]
www.splintered.co.uk | www.photographia.co.uk
http://redux.deviantart.com
__
Co-lead, Web Standards Project (WaSP) Accessibility Task Force
http://webstandards.org/
__
Take it to the streets ... join the WaSP Street Team
http://streetteam.webstandards.org/
__


***
List Guidelines: http://webstandardsgroup.org/mail/guidelines.cfm
Unsubscribe: http://webstandardsgroup.org/join/unsubscribe.cfm
Help: [EMAIL PROTECTED]
***



Re: [WSG] commenting javascript in script tags

2007-04-25 Thread Andrew Harris

On 4/26/07, Patrick H. Lauke [EMAIL PROTECTED] wrote:

Use external scripts, and you avoid both issues quite elegantly.


Thanks Patrick - I should point out that this question is mostly in
regards to a case where the bulk of the js is an external script. I
just need to occasionally insert a variable relevant to a particular
page. So, abhorrent as it might be, the script snippet has to live in
the head.

--
Andrew Harris
[EMAIL PROTECTED]
http://www.woowoowoo.com


***
List Guidelines: http://webstandardsgroup.org/mail/guidelines.cfm
Unsubscribe: http://webstandardsgroup.org/join/unsubscribe.cfm
Help: [EMAIL PROTECTED]
***