Welcome to WebmasterWorld Guest from 54.147.44.13

Forum Moderators: incrediBILL

Message Too Old, No Replies

Adding ID attribute to HTML tag

     
11:33 pm on Jul 9, 2012 (gmt 0)

Preferred Member

10+ Year Member Top Contributors Of The Month

joined:May 27, 2005
posts:428
votes: 3


I have a web page that is throwing errors due to the DOCTYPE statement negating its presence. HTML5 doesn't like this tag either. The ID is needed by a JavaScript and without it we get errors and code failure. This is the tag that we need...

<HTML id="xyz">

I think that I read or dreamed somewhere that an alternative might be to use JavaScript to declare this ID, but how?
12:02 pm on July 10, 2012 (gmt 0)

Administrator

WebmasterWorld Administrator phranque is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Aug 10, 2004
posts:10542
votes: 8


something like this might work:

var html=document.getElementsByTagName("HTML")[0];
html.setAttribute("id", "xyz");
12:12 pm on July 10, 2012 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Jan 29, 2002
posts:980
votes: 0


HTML5 allows the id attribute to be set on the <html> element, HTML4 didn't (but this rule doesn't affect parsing in browsers). So this is valid HTML5 code:


<!DOCTYPE html>
<HTML id="xyz">
<head>
<title></title>
</head>
<body>
<p></p>
</body>
</html>
1:17 pm on July 10, 2012 (gmt 0)

Preferred Member

10+ Year Member Top Contributors Of The Month

joined:May 27, 2005
posts:428
votes: 3


HTML5 allows the id attribute to be set on the <html> element


When I tested HTML5 and got an error about the ID not being defined in the JavaScript, I posted here. I'll try the JS method and hope that works.

But with JS, because it actions in the client browser, and because it runs between the head tags, wouldn't the opportunity to modify the html tag already have gone?
1:48 pm on July 10, 2012 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member fotiman is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Oct 17, 2005
posts: 4965
votes: 10


Don't use JavaScript for this unless it's something that's totally just a progressive enhancement. There's really no need for JavaScript in this example. The example that mattur posted is perfectly valid HTML5, with the id attribute defined in the markup as it should be.
1:12 am on July 11, 2012 (gmt 0)

Preferred Member

10+ Year Member Top Contributors Of The Month

joined:May 27, 2005
posts:428
votes: 3


Unfortunately the JavaScript on the page is crucial and it's failing to read that ID when it's hard coded while using the html5 tag and some other doctype tags.
5:15 am on July 11, 2012 (gmt 0)

Preferred Member

10+ Year Member Top Contributors Of The Month

joined:May 27, 2005
posts:428
votes: 3


After some more testing I found that the problem is not the method. Writing in the ID with JavaScript works just as well as hard coding the ID. The real problem is that HTML5 and some other DOCTYPE statements are killing the interaction between JavaScript and the browser plugin. All the JS is trying to do is get a signal from the plugin to say that it's completed loading. Otherwise that handshake works in all web browsers (except Chrome) by simply using...

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

without the usual "http://www.w3.org/TR/html4/loose.dtd" included.
1:34 pm on July 11, 2012 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member fotiman is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Oct 17, 2005
posts: 4965
votes: 10


What kind of plugin is this?
4:16 pm on July 11, 2012 (gmt 0)

Senior Member

WebmasterWorld Senior Member rocknbil is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Nov 28, 2004
posts:7999
votes: 0


I imagine you know that half-doctype puts the document into Quirks mode. Be ready for other oddities in various browsers. :-)
5:53 pm on July 11, 2012 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member fotiman is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Oct 17, 2005
posts: 4965
votes: 10


Right, what rocknbil said. You're just asking for even worse problems by running in Quirks mode.
11:46 pm on July 11, 2012 (gmt 0)

Preferred Member

10+ Year Member Top Contributors Of The Month

joined:May 27, 2005
posts:428
votes: 3


After further testing I now find that whereas the success of our handshake was dependent on doctype, the problem gets worse... browsers have become too unreliable. Before you could compensate for irregularities and those updates would be good for a couple of years. Now there is a danger of losing support within a month.

IE version is unlikely to change, but with Fool and Clown one could run a pool on guessing their version number available at the end of the year and there will not be many winners.
11:58 pm on July 11, 2012 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member fotiman is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Oct 17, 2005
posts: 4965
votes: 10


Do you have a more complete example of what you're trying to do? Perhaps moving this conversation to the JavaScript forum?
4:32 pm on July 12, 2012 (gmt 0)

Preferred Member

10+ Year Member Top Contributors Of The Month

joined:May 27, 2005
posts:428
votes: 3


No. It's a proprietary plugin that is needed to demonstrate the issue, and demonstration requires licensing. Anyway, we are dropping that support feature as it won't be needed by the time our team releases an alternative product.