OnClick can't be attached to via an XHTML externally referenced javascript file

VERIFIED INVALID

Status

()

P3
normal
VERIFIED INVALID
19 years ago
19 years ago

People

(Reporter: angjh, Assigned: nisheeth_mozilla)

Tracking

Trunk
x86
Windows NT
Points:
---

Firefox Tracking Flags

(Not tracked)

Details

Attachments

(2 attachments)

(Reporter)

Description

19 years ago
A document with the following starting fragment:

<?xml version="1.0"?>
<?xml-stylesheet href="somefile.css" type="text/css"?>

<Client	xmlns:html="http://www.w3.org/TR/REC-html40">
	<html:script type="text/javascript" language="javascript"
src="somefile.js"/>

That declares the following script in "somefile.js":

function document_onClick(evt) {
	alert("hey!");
}
document.onclick = document_onClick;

Should, when browsed through Mozilla, display an alert when clicked anywhere on
the document. This does not work. I also tried placing the code directly in the
script block instead of externally referencing it and this didn't seem to help
either. The ability to externalize behavior associated with XML elements is a
very powerful one (MS is cleanly hooking script to elements with DHTML
behaviors) and a must have for a solid web application development platform.
(Assignee)

Updated

19 years ago
Status: NEW → ASSIGNED
Target Milestone: M16
(Assignee)

Comment 1

19 years ago
This issue is related to whether an XHTML document exposes an HTML DOM or an XML 
DOM.  Currently, the XML DOM is exposed so "document.onclick" is not supposed to 
work in XHTML.  See bug 7833 for more discussion on this topic.  CCing Vidur 
for an update on what the DOM working group thinks about this.

Setting target milestone to M16...
(Assignee)

Updated

19 years ago
Depends on: 7833
(Assignee)

Comment 2

19 years ago
Moving bugs out by one milestone...
Target Milestone: M16 → M17
(Assignee)

Comment 3

19 years ago
On re-reading this bug, I feel that your test case is an XML document and will , 
therefore, never expose the HTML Document DOM.  So, document.onclick is never 
going to work for the case you described.

I think the real question to ask here is the following.  Do the DOM 2 event apis 
specify a way for scripts to listen to events inside XML documents.  If they do, 
what is the status of their implementation in Mozilla?  Re-assigning this bug to 
joki because he's the events god.
Assignee: nisheeth → joki
Status: ASSIGNED → NEW
(Assignee)

Comment 4

19 years ago
Created attachment 7962 [details]
test.xml
(Assignee)

Comment 5

19 years ago
Created attachment 7963 [details]
test.js
(Assignee)

Comment 6

19 years ago
Tom, if you save the attached test.xml and test.js in the same directory and 
load test.xml, you'll see a JS alert.  This means that the test.js file is 
getting loaded and executed properly.

Comment 7

19 years ago
Okay, funky.  So the problem isn't with the event listeners.  The problem is 
with the script running.  After the first alert dialog box runs the script 
stops.  I haven't looked into why yet.  I was going to recommend replacing the

document.onclick = document_onClick;
with
document.addEventListener("click", document_onClick, false);
per the DOM Level 2 spec but it actually seems that these both work, the problem 
is the alert box.  If you try putting two alert boxes in a row here you'll see 
that only one gets called.  Weird.  Well I'm going to bounce this back to you 
nisheeth for the script analysis.
Assignee: joki → nisheeth
(Assignee)

Comment 8

19 years ago
The test case works fine.  The document.onclick syntax is invalid inside an XML 
document because only the DOM Core interfaces are useable inside an XML 
document.

Marking bug invalid.
Status: NEW → RESOLVED
Last Resolved: 19 years ago
Resolution: --- → INVALID

Comment 9

19 years ago
Adding 'verifyme' keyword
Keywords: verifyme
Verified.
Status: RESOLVED → VERIFIED
Keywords: verifyme
You need to log in before you can comment on or make changes to this bug.