By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,605 Members | 2,153 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,605 IT Pros & Developers. It's quick & easy.

Dynamically Changing the DOCTYPE

P: n/a
I doubt this is possible, but I want to ask, just in case it is.

I have a project going using Google Maps. This project spits out an
HTML page template for people to post to their website and display a
map. Most of the people doing this will have limited knowledge of HTML.

I want to ensure that this page remains an XHTML 1.0 Transitional (or
Strict) page, in case some newbie removes the DOCTYPE or some slightly
more knowledgeable tries to change it to HTML 4.01 (which won't work
with the app).

I'm trying my best to make the app idiot-proof, even though all that
will do is cause the universe to create a bigger idiot.

Is it possible?

Jason

Oct 17 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
"DartmanX" <fe***********@gmail.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
I doubt this is possible, but I want to ask, just in case it is.

I have a project going using Google Maps. This project spits out an
HTML page template for people to post to their website and display a
map. Most of the people doing this will have limited knowledge of HTML.

I want to ensure that this page remains an XHTML 1.0 Transitional (or
Strict) page, in case some newbie removes the DOCTYPE or some slightly
more knowledgeable tries to change it to HTML 4.01 (which won't work
with the app).

I'm trying my best to make the app idiot-proof, even though all that
will do is cause the universe to create a bigger idiot.

Is it possible?

Jason


Could you just provide them a link to a page on your site?
Oct 17 '05 #2

P: n/a

DartmanX wrote:
I want to ensure that this page remains an XHTML 1.0 Transitional (or
Strict) page, in case some newbie removes the DOCTYPE or some slightly
more knowledgeable tries to change it to HTML 4.01 (which won't work
with the app).


So what do you want to do, simply parsing the string with the page
template for a DOCTYPE declaration to make sure the DOCTYPE declaration
is the one for XHTML 1.0 Transitional?
Or do you expect to be able to validate a string with markup against a
certain DTD?
Or is that page template loaded in a browser window and you want to use
the DOM to check whether there is a DOCTYPE declaration? For that you
can check e.g.

if (document.doctype) {
alert(document.doctype.name + '\r\n' + document.doctype.publicId +
'\r\n' + document.doctype.systemId)
}

where name would be
html
publicId
-//W3C//DTD XHTML 1.0 Transitional//EN
and systemId
http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd
for XHTML 1.0 Transitional.

But there is no requirement for document.doctype to be implemented in
HTML DOM implementations I think and IE/Win does not implement that
property. Mozilla however does, so does Opera 8. Not sure about support
in other browsers or older versions.

As for changing that with DOM methods, the W3C DOM Level 2 Core says:
"docType cannot be altered in any way, including through the use of
methods inherited from the Node interface, such as insertNode or
removeNode."

Mozilla 1.7 does not complain about doing

var newDoctype = document.implementation.createDocumentType(
'html',
'-//W3C//DTD XHTML 1.0 Transitional//EN',
'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'
);

if (document.doctype) {
document.doctype.parentNode.replaceChild(newDoctyp e, document.doctype);
}

but I don't think that change will achieve anything.

DOM Level 3 Core says something to that:
"This node can be set at document creation time and later changed
through the use of child nodes manipulation methods, such as
Node.insertBefore, or Node.replaceChild. Note, however, that while some
implementations may instantiate different types of Document objects
supporting additional features than the "Core", such as "HTML" [DOM
Level 2 HTML], based on the DocumentType specified at creation time,
changing it afterwards is very unlikely to result in a change of the
features supported."
--

Martin Honnen
http://JavaScript.FAQTs.com/
Oct 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.