Do most modern browsers support ids in script tags such as:
<script id="aParticularScript">/* ... */</script>
The reason I ask is that Eclipse displays a warning stating "undefined attribute name" but it works fine in Google Chrome when I use jQuery selectors to get other properties of the script element. W3Schools states that the script element does not support any standard attributes (including the id attribute), but I've learned not to trust W3Schools.
Is it okay to have the script tag have an id?
HTML 4 Answer:
No, you can't, at least not if you want valid HTML...
The following elements can't have an ID attribute:
<base>
<head>
<html>
<meta>
<script>
<style>
<title>
There might be a couple more.
This is confusing because viewing just the documentation for the ID/class attributes doesn't specifically say that they can't be used with these elements. You have to look at the DTD for the elements to see that the general attributes are not defined for the element, and thus cannot be used.
HTML 5 Answer:
The default document type declaration, HTMLElement, which applies to all elements in HTML specifies that these global attributes (including the ID attribute) can be used on any element you create, so it would appear you can do this in HTML 5, but not in HTML 4.
Running a <script> tag with an id through the validator as HTML4 generates this error:
Error Line 12, Column 12: there is no attribute "ID"
The HTML4 specification for <script> does not mention the coreattrs (that include class and id) to be valid on this element:
18.2.1 The SCRIPT element
<!ELEMENT SCRIPT - - %Script; -- script statements -->
<!ATTLIST SCRIPT
charset %Charset; #IMPLIED -- char encoding of linked resource --
type %ContentType; #REQUIRED -- content type of script language --
src %URI; #IMPLIED -- URI for an external script --
defer (defer) #IMPLIED -- UA may defer execution of script --
>
Start tag: required, End tag: required
According to the current HTML5 spec, <script> may have any Global Attributes which does include id. Testing this in an unofficial HTML5 validator passes. So as far as I can tell:
Invalid in HTML4
Valid in HTML5
Related
The Google+ JS API shows credentials and settings can be set using meta tags instead of passing through a JS call. Examples:
<meta name="google-signin-clientid" content="CLIENT_ID" />
<meta name="google-signin-cookiepolicy" content="single_host_origin" />
I tried this on my website and it works, but when I try to
validate my HTML the validator gives errors such as:
Bad value google-signin-callback for attribute name on element meta:
Keyword google-signin-callback is not registered.
Bad value google-signin-clientid for attribute name on element meta:
Keyword google-signin-clientid is not registered.
Bad value google-signin-cookiepolicy for attribute name on element
meta: Keyword google-signin-cookiepolicy is not registered.
Bad value google-signin-scope for attribute name on element meta:
Keyword google-signin-scope is not registered.
Is the HTML code Google provides as an example really invalid?
You are validating against HTML5 (this can be seen from the error messages), and as per HTML5 drafts, only a limited set of name attribute values are allowed in a meta element. So as an HTML5 document, the document is invalid, since the values used are among those allowed. HTML5 defines a registration procedure, but apparently Google cannot be bothered to use it.
If you validate against XHTML 1.0, the code will pass, because in XHTML 1.0, the name attribute value can be any name, like <meta name="Hi, I’m trying to make a point” content="" />. The same applies to HTML 4.01, except that the slash before “/” would cause a syntax error in it.
It's valid HTML, the names being used are not part of the official standard. That's fine though since they are namespaced with google so you shouldn't have any issues.
Im having an issue with custom attrubutes in html5 document.
My source code starts with the following code:
<!DOCTYPE html
[
<!ATTLIST img pid ID #IMPLIED>
]>
When im trying to validate my html file in W3C validator it doesnt determine my documents doctype and tells that my doctype declaration is wrong.
So my question is, how can I declare custom attributes in HTML5? Is it even possible at the moment in HTML5? I couldnt find any relevant information on the internet.
The DOCTYPE you are trying is invalid, it should be <!DOCTYPE html> which is a valid doctype for HTML5 and as far as the custom attributes go, you need to use data- prefix which will be considered as valid custom attribute.
<p data-custom-attribute="Value"></p>
[1] A custom data attribute is an attribute in no namespace whose name
starts with the string data-, has at least one character after the
hyphen, is XML-compatible, and contains no uppercase ASCII letters.
1. Reference
I found a strange a href in a webpage. It looks like
<a href=... rel="servername.com|6d63402c" ...other properties... ></a>
What does cryptic |6d63402c mean ? Is it a bitwise OR operation or just a string?
The document contains different links with different rels in this style.
The rel attribute specifies the link relationship type.
In HTML5 you may only use rel values that
are defined in the HTML5 specification, or
are registered in the Microformats wiki page existing rel values: HTML5 link type extensions.
As the value servername.com|6d63402c is not defined/registered, the page uses invalid markup.
As to what this specific value does: we can’t know (well, because it is not defined/registered). It’s probably some internal or third-party script that makes use of it. They should better use the data-* attribute instead of misusing rel.
Per the tag wiki:
The rel attribute is used in HTML elements to specify the relationship and connection between the current document and the linked document.
Sources: W3C (link)
Source: W3Schools (link)
First:
<meta http-equiv="refresh" content="0" url="http://www.google.com"/>
Second:
<meta http-equiv="refresh" content="0;URL=http://www.google.com"/>
The first one seems more sane, but does not work, while the second one works, but seems ill formed.
A meta tag with http-equiv is actually a way to put the *equiv*alent of a HTTP response header into a HTML page. A header in HTTP consists of field name and content, thus the second is in this case correct.
According to W3 schools (yeah, I know. Not the best source according to some know-it-alls, around here) the Meta tag only has 5 supported attributes:
charset (html5 only) : Specifies the character encoding for the HTML document
content : Gives the value associated with the http-equiv or name attribute
http-equiv : Provides an HTTP header for the information/value of the content attribute
name : Specifies a name for the metadata
scheme (not in html5) : Specifies a scheme to be used to interpret the value of the content attribute
The main difference is, as you say, that the latter (often) works, the former does not. The former does not comply with any HTML specification or draft either; there is no attribute named url in HTML. (Attributes that take URL values have names like href and scr, by the way.)
The latter is in principle more vague in HTML specs and drafts. HTML 4.01 mentions the construct indirectly, without giving the exact form: “Some user agents support the use of META to refresh the current page after a specified number of seconds, with the option of replacing it by a different URI. Authors should not use this technique to forward users to different pages, as this makes the page inaccessible to some users. Instead, automatic page forwarding should be done using server-side redirects.”
But HTML5 CR more realistically describes the construct and its function in detail and declares it as conforming.
From the HTML perspective, the value of the content attribute is just a string, which may be subject to rules defined in other specifications. In this case, the odd format imitates an HTTP header, which was originally introduced by Netscape, later widely supported by browsers though never standardized in HTTP specifications.
David crockford recommends ommitting the type="application/javascript" attribute for the script tag. Should I do the same for a CSS link tag (omit "type=text/css")? I googled "html link omit mime type" and some variants and didn't find anything
Per documentation for <script>:
The type attribute gives the language of the script or format of the data. If the attribute is present, its value must be a valid MIME type. The charset parameter must not be specified. The default, which is used if the attribute is absent, is "text/javascript".
Now, let's take a look at <link>:
The default value for the type attribute, which is used if the attribute is absent, is "text/css".
The specification is not clear on this for some reason, but it does contain this:
Since that default type is text/css...
The type attribute is also purely advisory. Modern browsers definitely don't need it if it's valid CSS.
There is no practical reason to use the type attribute in either script or link elements, when you are using JavaScript and CSS, as you are (almost always). However, if there is an external requirement imposed upon you to conform to the HTML 4.01 specification, use type="text/javascript" in script, and double-check that you enter it correctly.
Those attributes are never needed (for JavaScript and CSS), but they hurt you if you misspell them. Then browsers will expect that your script is in text/javascript or your style sheet is in text/ccs and ignore it, since they do not know such languages.
In a script element, you would need a type attribute only if the content is not to be interpreted as JavaScript but e.g. as VBScript or not interpreted at all, just stored as data.