From: Axel Dahmen on
Hi,

I'd like to create a HTML document from scratch, but I don't know how to
create a "<!DOCTYPE HTML>" element.

Can someone please enlighten me?

Your help is appreciated.
Axel Dahmen

From: Sean Kinsey on
On Apr 3, 3:26 pm, "Axel Dahmen" <KeenToK...(a)newsgroup.nospam> wrote:
> Hi,
>
> I'd like to create a HTML document from scratch, but I don't know how to
> create a "<!DOCTYPE HTML>" element.
>
> Can someone please enlighten me?
>
> Your help is appreciated.
> Axel Dahmen

The doctype attribute is readonly and cannot be changed after the
document has been parsed.
But if you are creating a dynamic document, then just use
document.write("<!doctype..."). An example can bee seen at
http://bolinfest.com/javascript/iframe_with_doctype.html
From: Axel Dahmen on
"Sean Kinsey" <okinsey(a)gmail.com> schrieb im Newsbeitrag
news:3fd5d290-48b1-4c3b-9478-7f11d2ef91a0(a)e7g2000yqf.googlegroups.com...
> On Apr 3, 3:26 pm, "Axel Dahmen" <KeenToK...(a)newsgroup.nospam> wrote:
> The doctype attribute is readonly and cannot be changed after the
> document has been parsed.
> But if you are creating a dynamic document, then just use
> document.write("<!doctype..."). An example can bee seen at
> http://bolinfest.com/javascript/iframe_with_doctype.html

I understand... - Great, thanks a lot for the hint! I was so focussed on DOM
manipulation that I didn't even think of this straight-forward approach.

Cheers,
Axel Dahmen

From: Martin Honnen on
Axel Dahmen wrote:

> I'd like to create a HTML document from scratch, but I don't know how to
> create a "<!DOCTYPE HTML>" element.
>
> Can someone please enlighten me?

I don't think the W3C DOM API supports creating HTML 4 documents from
scratch but you can create an XHTML 1.0 document as follows (in browsers
like Mozilla, Opera, Safari):

var xhtmlNs = 'http://www.w3.org/1999/xhtml';

var doc = document.implementation.createDocument(xhtmlNs, 'html',
document.implementation.createDocumentType('html', '-//W3C//DTD XHTML
1.0 Strict//EN', 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'));

var head = doc.documentElement.appendChild(doc.createElementNS(xhtmlNs,
'head'));
var title = head.appendChild(doc.createElementNS(xhtmlNs, 'title'));
title.appendChild(doc.createTextNode('Example'));

// add further nodes here


--

Martin Honnen
http://msmvps.com/blogs/martin_honnen/
From: Thomas 'PointedEars' Lahn on
Sean Kinsey wrote:

> "Axel Dahmen" wrote:
>> I'd like to create a HTML document from scratch, but I don't know how to
>> create a "<!DOCTYPE HTML>" element.
>>
>> Can someone please enlighten me?
>
> The doctype attribute is readonly and cannot be changed after the
> document has been parsed.

There is no "doctype attribute" in implementations. There is a `doctype'
property.

> But if you are creating a dynamic document, then just use
> document.write("<!doctype..."). An example can bee seen at
> http://bolinfest.com/javascript/iframe_with_doctype.html

Another possibility is using a `data:' URI for the location of a Window.


PointedEars
--
realism: HTML 4.01 Strict
evangelism: XHTML 1.0 Strict
madness: XHTML 1.1 as application/xhtml+xml
-- Bjoern Hoehrmann