Safari, innerHTML and XHTML

R

RobG

It seems that Safari doesn't implement the innerHTML property for
dynamically created elements in XHTML documents, although it does work
for in-line elements.

It also seems that Safari uses the file extension to detect XHTML
rather that the DOCTYPE. There's a test case below, save it to files
with .xhtml and .html extensions and open in Safari to see the
difference. Tested in 3 on Mac.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/
TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>innerHTML test</title>
<script type="text/javascript">//<![CDATA[
function foo() {
var div = document.createElement('div');
var div1 = document.getElementById('div1');
var div2 = document.getElementById('div2');
div1.innerHTML = 'In-line div worked';
div2.appendChild(div);
div.innerHTML = "Scripted div worked.";
}
window.onload = foo;
// ]]></script>
</head>
<body>
<div id="div1"></div>
<div id="div2"></div>
</body>
</html>
 
M

Martin Honnen

RobG said:
It seems that Safari doesn't implement the innerHTML property for
dynamically created elements in XHTML documents, although it does work
for in-line elements.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/
TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>innerHTML test</title>
<script type="text/javascript">//<![CDATA[
function foo() {
var div = document.createElement('div');

If you want to script XHTML as XML then you should use
var div =
document.createElementNS('http://www.w3.org/1999/xhtml', 'div');
to create an XHTML DIV element.
I have not tested whether that helps with Safari but don't expect a div
element in no namespace to have an innerHTML property. And with an XML
document document.createElement('div') does create a div element in no
namespace.
 
T

Thomas 'PointedEars' Lahn

Martin said:
RobG said:
It seems that Safari doesn't implement the innerHTML property for
dynamically created elements in XHTML documents, although it does work
for in-line elements.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/
TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>innerHTML test</title>
<script type="text/javascript">//<![CDATA[
function foo() {
var div = document.createElement('div');

If you want to script XHTML as XML then you should use
var div =
document.createElementNS('http://www.w3.org/1999/xhtml', 'div');
to create an XHTML DIV element.

That is not quite correct, because `document' would be a reference to an
object that implements the HTMLDocument interface. However, W3C DOM Level 2
HTML, where this interface is defined, only applies to both HTML 4.01 and
XHTML 1.0 documents, not to XHTML _1.1_ documents.
I have not tested whether that helps with Safari but don't expect a div
element in no namespace to have an innerHTML property. And with an XML
document document.createElement('div') does create a div element in no
namespace.

Non sequitur. An `innerHTML' attribute is not defined by any W3C DOM
interface to date; that property is the result of a proprietary
augmentation, so the namespace really should not matter. However, it is
reasonable that XHTML 1.1 element objects would not have such a property
in Safari; it is `inner*HTML*', after all.

That said, it also depends which version of Safari 3 the OP tested with;
while Safari 3.0.4 was released for Mac OS X v10.5, Safari 3.0.3 is still
beta. In any case, the observed behavior may as well be a bug.


PointedEars
 
T

Thomas 'PointedEars' Lahn

Randy said:
Martin Honnen said the following on 11/11/2007 7:52 AM:
If you want to script XHTML as XML then you should use
var div =
document.createElementNS('http://www.w3.org/1999/xhtml', 'div');
to create an XHTML DIV element.
I have not tested whether that helps with Safari but don't expect a div
element in no namespace to have an innerHTML property. And with an XML
document document.createElement('div') does create a div element in no
namespace.

Changing it in a file with an .xhtml extension allows it to set the
innerHTML property as desired in the Windows version, [...]

I would consider that a bug, because one problem with innerHTML is that it
is inner*HTML*. It is not supposed to support element minimization and
namespaces, for example.


PointedEars
 
R

RobG

Martin Honnen said the following on 11/11/2007 7:52 AM:


RobG said:
It seems that Safari doesn't implement the innerHTML property for
dynamically created elements in XHTML documents, although it does work
for in-line elements.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/
TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>innerHTML test</title>
<script type="text/javascript">//<![CDATA[
function foo() {
var div = document.createElement('div');
If you want to script XHTML as XML then you should use
var div =
document.createElementNS('http://www.w3.org/1999/xhtml', 'div');
to create an XHTML DIV element.
I have not tested whether that helps with Safari but don't expect a div
element in no namespace to have an innerHTML property. And with an XML
document document.createElement('div') does create a div element in no
namespace.

Changing it in a file with an .xhtml extension allows it to set the
innerHTML property as desired in the Windows version, Rob will have to
test the mac version.

Yes, that works in Safari (3.0.3) on Mac too. I was doing this out of
interest, it is a quirk that someone pointed out to me and I figured
that I'd get an answer here. :)

Thank you to all who replied.
 

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

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,189
Members
46,734
Latest member
manin

Latest Threads

Top