P
Patient Guy
I am trying to write functions that manipulate objects representing
dynamic tables in HTML documents in a more friendly way (to me).
I do this by creating a table object (tableObject) through a constructor
(code below) whose properties include .rows and .columns and arrays
corresponding to cells, and I can just set/get values (probably through
methods) to change the tables, with other functions adding and pruning
DOM-related nodes to the table as the case may be.
Within the constructor, I am trying to call a function described in the
DOM Traversal specification for walking the nodes of the table tree, but I
am getting an error:
Error: Object cannot be created in this context =
NS_ERROR_DOM_NOT_SUPPORTED_ERR
The function being called is a NodeFilter constructor related to the
Traversal spec. The system/browser being used is Firefox 1.5.0.4, which
apparently implements this constructor, since I have included code which
attempts to define the constructor IF it is not implemented/defined by
other systems/browsers, and FF is returning the error (not my code).
Anyone have an idea what the error is and what may be causing it?
Google has a scarcity of results and none I can find that actually
describe under what conditions the error code is/might be returned. I
can't even find anything on the Mozilla site.
============= code fragment start ===============
/*
the tableObject constructor for an existing table document object
--- argument 'documentID' is the value of the 'id' attribute of the
table element in the HTML document which is to be characterized and
manipulated
*/
function tableObject(documentID)
{
var i, node, collection;
if ((this.docObject = node = document.getElementById(documentID)) ==
null)
return (null);
if (node.nodeName.toLowerCase() != "table")
return (null);
this.type = "tableObject";
this.documentID = documentID;
this.getDocumentId = function () {
return (this.documentID);
};
this.getNode = function () {
return (this.docObject);
};
// store the THEAD, TBODY, TFOOT and their TR and TH/TH nodes for
// dynamic table
/* The line immediately below calling a NodeFilter constructor
is the one producing the error
Error: Object cannot be created in this context =
NS_ERROR_DOM_NOT_SUPPORTED_ERR
*/
var nodeFilter = new NodeFilter(collectionsFilter);
var twalk = document.createTreeWalker(node, NodeFilter.SHOW_ELEMENT,
nodeFilter, false);
if (typeof(childNodeType) != "string")
{
var i;
if (typeof(childNodeType) != "object" ||
typeof(childNodeType.length) == "undefined")
return (null);
}
return (this);
}
function collectionsFilter(node, whatToFilter)
{
if (typeof(node) == "undefined" ||
typeof(whatToFilter) == "undefined")
return (NodeFilter.FILTER_REJECT);
if (node.getNodeType() == Node.ELEMENT_NODE)
for (i = 0; i < whatToFilter.length; i++)
if (node.getNodeName().toLowerCase() ==
whatToFilter.toLowerCase())
return (NodeFilter.FILTER_ACCEPT);
return (NodeFilter.FILTER_SKIP);
}
dynamic tables in HTML documents in a more friendly way (to me).
I do this by creating a table object (tableObject) through a constructor
(code below) whose properties include .rows and .columns and arrays
corresponding to cells, and I can just set/get values (probably through
methods) to change the tables, with other functions adding and pruning
DOM-related nodes to the table as the case may be.
Within the constructor, I am trying to call a function described in the
DOM Traversal specification for walking the nodes of the table tree, but I
am getting an error:
Error: Object cannot be created in this context =
NS_ERROR_DOM_NOT_SUPPORTED_ERR
The function being called is a NodeFilter constructor related to the
Traversal spec. The system/browser being used is Firefox 1.5.0.4, which
apparently implements this constructor, since I have included code which
attempts to define the constructor IF it is not implemented/defined by
other systems/browsers, and FF is returning the error (not my code).
Anyone have an idea what the error is and what may be causing it?
Google has a scarcity of results and none I can find that actually
describe under what conditions the error code is/might be returned. I
can't even find anything on the Mozilla site.
============= code fragment start ===============
/*
the tableObject constructor for an existing table document object
--- argument 'documentID' is the value of the 'id' attribute of the
table element in the HTML document which is to be characterized and
manipulated
*/
function tableObject(documentID)
{
var i, node, collection;
if ((this.docObject = node = document.getElementById(documentID)) ==
null)
return (null);
if (node.nodeName.toLowerCase() != "table")
return (null);
this.type = "tableObject";
this.documentID = documentID;
this.getDocumentId = function () {
return (this.documentID);
};
this.getNode = function () {
return (this.docObject);
};
// store the THEAD, TBODY, TFOOT and their TR and TH/TH nodes for
// dynamic table
/* The line immediately below calling a NodeFilter constructor
is the one producing the error
Error: Object cannot be created in this context =
NS_ERROR_DOM_NOT_SUPPORTED_ERR
*/
var nodeFilter = new NodeFilter(collectionsFilter);
var twalk = document.createTreeWalker(node, NodeFilter.SHOW_ELEMENT,
nodeFilter, false);
if (typeof(childNodeType) != "string")
{
var i;
if (typeof(childNodeType) != "object" ||
typeof(childNodeType.length) == "undefined")
return (null);
}
return (this);
}
function collectionsFilter(node, whatToFilter)
{
if (typeof(node) == "undefined" ||
typeof(whatToFilter) == "undefined")
return (NodeFilter.FILTER_REJECT);
if (node.getNodeType() == Node.ELEMENT_NODE)
for (i = 0; i < whatToFilter.length; i++)
if (node.getNodeName().toLowerCase() ==
whatToFilter.toLowerCase())
return (NodeFilter.FILTER_ACCEPT);
return (NodeFilter.FILTER_SKIP);
}