473,604 Members | 2,483 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Does <script src=foo> require an end tag </script>

W3C HTML validator passes this:

....
<script type="text/javascript" src="foo.js">

<script type="text/javascript">
....script in here...
</script>
....

But as far as I can tell, the first script tag requires a </script>
close tag. Is the close tag required for valid markup? I know browsers
accept this, but that's not the question. Is it valid?

Apr 8 '06 #1
44 2811
rh*******@gmail .com writes:
W3C HTML validator passes this:
Here's your SCRIPT element type start tag:
<script type="text/javascript" src="foo.js">
Here's some arbitrary CDATA content:
<script type="text/javascript">
...script in here...
Here's your SCRIPT element type end tag:
</script>
Next time, enable 'view parse tree' (or whatever it is called, I can't
be bothered to have a look).
But as far as I can tell, the first script tag requires a </script>
close tag.
Yes. Well, end tag.
Is the close tag required for valid markup?
Yes.
I know browsers
accept this,
Ah. I don't, I have too many of them to make generalised statements
about their treatment of generalized markup.
but that's not the question. Is it valid?


Yes.
(who cares?)
--
||| hexadecimal EBB
o-o decimal 3771
--oOo--( )--oOo-- octal 7273
205 goodbye binary 111010111011
Apr 8 '06 #2
rhythmace wrote:
<script type="text/javascript" src="foo.js">

<script type="text/javascript">
...script in here...
</script>
...

But as far as I can tell, the first script tag requires a </script>
close tag. Is the close tag required for valid markup?


Yes -- the SCRIPT element requires an end tag. But you have an end tag
there.

The real question, is "how many SCRIPT elements do you have there?" The
answer is one.

The second "<script... " bit will be treated as Javascript data within the
first SCRIPT element, and should cause a Javascript error (but not a
validation error).

--
Toby A Inkster BSc (Hons) ARCS
Contact Me ~ http://tobyinkster.co.uk/contact

Apr 8 '06 #3
VK

rh*******@gmail .com wrote:
<script type="text/javascript" src="foo.js">

<script type="text/javascript">
...script in here...
</script>


That was already explained why such script declaration will not work.
I'd just like to alert you about another common mistake of this kind:

<script type="text/javascript" src="foo.js">
// code here
</script>

// code here block will be ignored and only foo.js code will be
executed (unless it's Netscape 2.x w/o src attribute support)

So the rule is: external file requires separate <script> block with
closing tag.

The only working option:

<script type="text/javascript" src="foo.js"></script>
<script type="text/javascript">
// code here
</script>

Apr 8 '06 #4
Excellent! Thanks so much guys. Actually the browsers appear to be
smart about this and afaict they do interpret 2 script tags, not 1, so
they might have some heuristic. For example, if it is not possible to
nest script tags then maybe they just autoclose the first one???

Apr 8 '06 #5
VK

rh*******@gmail .com wrote:
Actually the browsers appear to be
smart about this and afaict they do interpret 2 script tags, not 1, so
they might have some heuristic.


No they don't: it is your allusion. Probably you happened to have a
variable/function you're checking against both in external file and in
inline code.

Any way: your syntax doesn't work (and cannot work), so please stop
confusing potentional readers ;-) :-|

A code to dismiss your allusion:

// THIS SYNTAX IS INTENTIONALLY WRONG
// FOR DEMONSTRATION PURPOSES

<html>
<head>
<title>Test</title>
<meta http-equiv="Content-Type"
content="text/html; charset=iso-8859-1">
<script type="text/javascript" src="foo.js" />
<script type="text/javascript">
var v = 1;
</script>
</head>

<body onLoad="alert(t ypeof v)">

</body>
</html>

// FF 1.5.0.1 : undefined
// IE 6.0 : undefined
// Opera 8.5 : undefined
And for a sake of it:
// NN 4.5 : undefined

Apr 9 '06 #6
VK wrote:
// THIS SYNTAX IS INTENTIONALLY WRONG
// FOR DEMONSTRATION PURPOSES
[...] <script type="text/javascript" src="foo.js" />
<script type="text/javascript">
var v = 1;
</script>


That should actually be fine, assuming XHTML.

--
Toby A Inkster BSc (Hons) ARCS
Contact Me ~ http://tobyinkster.co.uk/contact

Apr 12 '06 #7
VK

Toby Inkster wrote:
VK wrote:
// THIS SYNTAX IS INTENTIONALLY WRONG
// FOR DEMONSTRATION PURPOSES

[...]
<script type="text/javascript" src="foo.js" />
<script type="text/javascript">
var v = 1;
</script>


That should actually be fine, assuming XHTML.


Of course it is *not*. The parsing rules get stricter, but the basics
are the same. <script> tag requires closing tag. After meeting <script
type="text/javascript" src="foo.js" /> UA will ignore everything until
it meets the closing tag </script>. This way the internal block will be
ignored.

You seem to have a strange idea about the /> syntax. It is not (and
cannot be) used to override (X)HTML standards - say to transform a
paired tag into a single one against specifications. Why wouldn't you
try to use then <div />Content 1 <div />Content 2

Apr 12 '06 #8
On 12/04/2006 21:58, VK wrote:
Toby Inkster wrote:
VK wrote:
[snip]
<script type="text/javascript" src="foo.js" />

[snip]
That should actually be fine, assuming XHTML.


Of course it is *not*.


Yes, it is. Toby said XHTML, not HTML.

[snip]

Mike

--
Michael Winter
Prefix subject with [News] before replying by e-mail.
Apr 12 '06 #9
VK
> <script type="text/javascript" src="foo.js" />
<script type="text/javascript">
var v = 1;
</script>

Michael Winter wrote: Yes, it is <fine>. Toby said XHTML, not HTML.


What do you mean by "fine"? That it will pass XHTML validation on W3C
validator? Yes it currently will because there is obviously a bug in
the current version. It allows you to use the /> syntacs against the
declared DTD - thus in paired tags. After the validator will learn to
pay more attention to the declared DTD's, this issue will be solved.

If by "fine" you mean "will produce the intended result" - then of
course and once again *no*. From two declared blocks above anly the
external file foo.js will be loaded.

Apr 12 '06 #10

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

Similar topics

7
1442
by: John Bailo | last post by:
how come I can say: if() statement; else statement; but I cannot say try statment; catch() statement;
0
1311
by: trexim | last post by:
Hi, I have a rpc operation in my WSDL: <operation name="My-Function"> <documentation>Some misc function of mine</documentation> <input message="tns:myFunctionRequest"/> <output message="tns:myFunctionResponse"/> <fault name="FaultName" message="tns:negResponse"/> </operation>
0
1670
by: John Haigh | last post by:
Should possibly have an "add" method in a PostingObject class in the constructor of PostingObject. will call to add a Posting to the ? Does this make sense? My sense is that a PostingObject needs a Posting, so would I do this in the PostingObject Constructor? Here is my code: using System; using System.Collections; using Microsoft.ContentManagement.Publishing;
4
1254
by: Peter Rilling | last post by:
I am creating a website that uses Forms Authentication. From what I have read, FA uses cookies to store the authentication ticket once logged in. My customer would also like this site to not require cookies. Does FA require the use of cookies or can I use some other mechanism when I set the system to use cookieless sessions?
0
1123
by: citystud | last post by:
does C# support vector< vector<int> > ?if not how can i use vector?
4
2546
by: 1965 | last post by:
Hi,All. I want to click a string, then pass the string to asp file, where I use function to get a remote xml file, and then use brower to parse this xml file. But it doe not work. Is the code right? <a href="rssxml1.asp?ITEM=1" onclick="loadnews()">stringA </a> <a href="rssxml1.asp?ITEM=2" onclick="loadnews()">stringB </a> Is that right? The problem is that I can get remote xml file in browser but loadnews() function does not execute,...
21
1441
by: Ray Cassick | last post by:
I can't believe why I had not noticed this before and why I never asked it before... When defining a string why is it not required to use the new keyword? Like: Dim a As String = New String You can do it when using the string type with some arguments in the constructor but it look like there is no empty constructor on the String class.
21
1492
by: google | last post by:
Hello, in embedded programming, different kinds of memory exist, e.g. RAM and ROM (Flash memory). For a class containing variables and constant values one might want to put the variables in RAM and the constants in ROM, which means that the object is split into different parts in memory. Besides from the fact that the current compiler does not support such feature: does the C++ standard require an that the objects data
0
7929
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8065
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8280
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
5882
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5441
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3955
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2434
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
1526
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1266
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.