473,387 Members | 1,611 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,387 software developers and data experts.

Perferred way to embed javascript into xhtml

1.

<script type="text/javascript">
alert("test");
</script>

2.

<script type="text/javascript">
<!--//
alert("test");
//-->
</script>

3.

<script type= "text/javascript">/*<![CDATA[*/
alert("test");
/*]]>*/</script>

which one you prefer? (assume xhtml transitional)
thanks.

Apr 15 '07 #1
4 2778
howa said the following on 4/15/2007 4:07 AM:
1.

<script type="text/javascript">
alert("test");
</script>
2.
<script type="text/javascript">
<!--//
alert("test");
//-->
</script>
3.
<script type= "text/javascript">/*<![CDATA[*/
alert("test");
/*]]>*/</script>
which one you prefer?
<script type="text/javascript" src="myExternalFile.js"></script>
(assume xhtml transitional)
xHTML isn't a good choice on the web though.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Apr 15 '07 #2
On 4月15日, 下午10時13分, Randy Webb <HikksNotAtH...@aol.comwrote:
howa said the following on 4/15/2007 4:07 AM:


1.
<script type="text/javascript">
alert("test");
</script>
2.
<script type="text/javascript">
<!--//
alert("test");
//-->
</script>
3.
<script type= "text/javascript">/*<![CDATA[*/
alert("test");
/*]]>*/</script>
which one you prefer?

<script type="text/javascript" src="myExternalFile.js"></script>
assuming the scripts will only be called once for that page, external
JS seems not a good solutions.
(assume xhtml transitional)

xHTML isn't a good choice on the web though.
maybe until HTML5 ?
Apr 15 '07 #3
howa wrote:
1.

<script type="text/javascript">
alert("test");
</script>
Because in XHTML the content of a script element is PCDATA the above is
completely acceptable, but if the script contained characters that were
meaningful to the XML parser they would need to be transformed into
their corresponding mark-up entities. Most real scripts would contain
such characters.
2.

<script type="text/javascript">
<!--//
alert("test");
//-->
</script>
In PCDATA processing instructions are interpreted as processing
instructions and so comments they contain are interpreted as comments.
Comments may be stripped out by an XML parser but even if they were not
there should be no expectation of their contents being passed on to a
javascript interpreter. The above is just wrong in an XHTML (and all
otehr XML) context(s).
3.

<script type= "text/javascript">/*<![CDATA[*/
alert("test");
/*]]>*/</script>
Wrapping <![CDATA[ ... ]]around the script contents means that
characters that may be significant to the mark-up will be disregarded
(except the "]]>" sequence, which is a potentially valid construct in
javascript, such as in - if(a[b[c]]>2){ ... } -)).

It is utterly redundant to javascript style multi-line comments around
the CDATA mark-up in an XHTML document.
which one you prefer? (assume xhtml transitional)
The preferable approach is to realise that while IE browsers do not
support XHTML that mark-up flavour has no value in a commercial context
as something to be sending to web browsersl. And so use only HTML, where
the contents of SCRIPT elements are CDATA by definition.

If XHTML is to be used the only sensible option is to import the scripts
into the document, and so avoid all questions of what the XML parser may
make of the characters used.

Richard.

Apr 15 '07 #4
howa said the following on 4/15/2007 2:01 PM:
On 415, 銝1013, Randy Webb <HikksNotAtH...@aol.comwrote:
>howa said the following on 4/15/2007 4:07 AM:


>>1.
<script type="text/javascript">
alert("test");
</script>
2.
<script type="text/javascript">
<!--//
alert("test");
//-->
</script>
3.
<script type= "text/javascript">/*<![CDATA[*/
alert("test");
/*]]>*/</script>
which one you prefer?
<script type="text/javascript" src="myExternalFile.js"></script>

assuming the scripts will only be called once for that page, external
JS seems not a good solutions.
Say again? External scripts with xHTML are *always* a good solution.
>>(assume xhtml transitional)
xHTML isn't a good choice on the web though.
maybe until HTML5 ?
That isn't up to me, it isn't even up to the W3C, it is up to the people
in Redmond Washington, USA.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Apr 15 '07 #5

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

Similar topics

1
by: Sergio del Amo | last post by:
Hi, I post here because, i think that my problem can happen to a lot of people using javascript with xml and xsl and the future feedback can be useful to all of us. I hava an xml file with a...
3
by: Tony Sutton | last post by:
I have this following code in my html file: <object classid="clsid:166B1BCA-3F9C-11CF-8075-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/director/sw.cab#...
10
by: Anna | last post by:
Hi all. I don't have a very deep understanding of CSS and this question might sound stupid for you. Sorry for that. Can the overflow CSS property be applied to the embed tag? I have an embed...
7
by: Trvl Orm | last post by:
I am working with 2 frames, Left and Right and the main code is in the left frame, which has been attached. Can someone please help me with this code. I am new to JavaScript and can't figure it...
6
by: ged | last post by:
Hi, i am a oo (c#) programmer, and have not used javascript for a while and i cant work out how javascript manages its references. Object References work for simple stuff, but once i have an...
8
by: jalexa9898 | last post by:
I am asking because I wrote some flex that was put in xml and I want to embed it in some html is this hard to do?
6
by: qualitychecker | last post by:
Hello thanks for your help.. I try to reference a PHP module from within a HTML file, see below ---------------------------------------- <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr">...
4
by: csgraham74 | last post by:
Ok - i was wondering if someone could help me. im basically trying to embed an html string in piece of XML. i created an xsl and added the CDATA into the xml around the html i wish to render....
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
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,...

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.