473,545 Members | 2,686 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2783
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="myExternal File.js"></script>
(assume xhtml transitional)
xHTML isn't a good choice on the web though.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javas cript 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="myExternal File.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="myExternal File.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.javas cript 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
4446
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 tree structure and a xsl file to transform it into xhtml strict. In my file xsl i have: <head> <title>Generic XHTML Treeview</title> <meta...
3
5207
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# version=7,0,0,0" width="320" height="320"> <param name="src" value="file.dcr" /> <embed src="file.dcr"...
10
6294
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 tag whose source is big SVG file, whose dimensions are unknown. If it is bigger than the screen, the rest of the SVG is clipped and not shown. I...
7
1965
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 out. What needs to happen is this: On the left frame you should have a series of buttons, which when pushed makes things happen on the right...
6
5570
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 object collection and stanrd using it it starts to fall apart. Clearly there is something about javascript's usage of passing "By ref" that i am not...
8
2443
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
2369
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"> <head> <titleMy title </title> </head> <body> on place un embed <embed id="embed1" alt="ne marche pas..." src="ws.php?
4
4265
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. In my calling page i create an XML data island (excuse the terminology as im new to this stuff) to pull in the xml fields and to hopefully render...
0
7496
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, well explore What is ONU, What Is Router, ONU & Routers main...
0
7685
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
7941
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
7784
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
6014
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 projectplanning, coding, testing, and deploymentwithout human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
3467
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1916
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
1039
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
738
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.