Dynamically Changing the DOCTYPE

D

DartmanX

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
 
M

McKirahan

DartmanX said:
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?
 
M

Martin Honnen

DartmanX said:
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(newDoctype, 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."
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,900
Latest member
Nell636132

Latest Threads

Top