Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Address elements from custom namespace in IE

Reply
Thread Tools

Address elements from custom namespace in IE

 
 
VK
Guest
Posts: n/a
 
      10-26-2005
I have this code failing to work in IE: getElementsByTagName doesn't
return elements from my JS namespace. What's wrong?


<html xmlns:js>
<head>
<title>Que</title>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1">

<style type="text/css">
<!--
body { background-color: #FFFFFF}
@media all {
js\:link { font-style: italic; color: #0000FF; text-decoration:
underline; cursor: hand; cursor: pointer}
}
-->
</style>

<script type="text/javascript">
<!--
function normalizeLinks(){
var jsLink = document.getElementsByTagName('JS:LINK');
// The method above doesn't work with IE
// IE has some fancy twist I have to be reminded again
for (i=0; i<jsLink.length; i++) {
jsLink[i].title = '';
jsLink[i].style.fontStyle = 'normal';
}
}

if ('addEventListener' in self) {
self.addEventListener('load',normalizeLinks,false) ;
}
else {
self.attachEvent('onload',normalizeLinks);
}
//-->
</script>

</head>

<body>

<p>
<a href="http://www.mozilla.org/products/firefox/">Mozilla Firefox</a>
</p>

<p>
<js:link title="JavaScript function call..."
onclick="alert('Booh!')">JavaScript call 1</js:link>
</p>

<p>
<a href="http://www.microsoft.com/windows/ie/default.mspx">Microsoft
Internet Explorer</a>
</p>

<p>
<js:link title="JavaScript function call..." onclick="alert('Booh
again!')">JavaScript call 2</js:link>
</p>

<p>
<a href="http://browser.netscape.com/ns8/">Netscape Navigator</a>
</p>

<p>
<js:link title="JavaScript function call..." onclick="alert('Booh
again!')">JavaScript call 3</js:link>
</p>
</body>
</html>

 
Reply With Quote
 
 
 
 
Martin Honnen
Guest
Posts: n/a
 
      10-26-2005


VK wrote:

> I have this code failing to work in IE: getElementsByTagName doesn't
> return elements from my JS namespace. What's wrong?
>
>
> <html xmlns:js>


> var jsLink = document.getElementsByTagName('JS:LINK');
> // The method above doesn't work with IE


> <js:link title="JavaScript function call..."
> onclick="alert('Booh!')">JavaScript call 1</js:link>


Does it help if you use an <?IMPORT> processing instruction
<http://msdn.microsoft.com/library/default.asp?url=/workshop/author/dhtml/reference/pi/import.asp>
to bind that prefix?

--

Martin Honnen
http://JavaScript.FAQTs.com/
 
Reply With Quote
 
 
 
 
web.dev
Guest
Posts: n/a
 
      10-26-2005

VK wrote:
> I have this code failing to work in IE: getElementsByTagName doesn't
> return elements from my JS namespace. What's wrong?
>
>
> <html xmlns:js>
> <head>
> <title>Que</title>
> <meta http-equiv="Content-Type" content="text/html;
> charset=iso-8859-1">
>
> <style type="text/css">
> <!--
> body { background-color: #FFFFFF}
> @media all {
> js\:link { font-style: italic; color: #0000FF; text-decoration:
> underline; cursor: hand; cursor: pointer}
> }
> -->
> </style>
>
> <script type="text/javascript">
> <!--
> function normalizeLinks(){
> var jsLink = document.getElementsByTagName('JS:LINK');
> // The method above doesn't work with IE
> // IE has some fancy twist I have to be reminded again
> for (i=0; i<jsLink.length; i++) {
> jsLink[i].title = '';
> jsLink[i].style.fontStyle = 'normal';
> }
> }
>
> if ('addEventListener' in self) {
> self.addEventListener('load',normalizeLinks,false) ;
> }
> else {
> self.attachEvent('onload',normalizeLinks);
> }
> //-->
> </script>
>
> </head>
>
> <body>
>
> <p>
> <a href="http://www.mozilla.org/products/firefox/">Mozilla Firefox</a>
> </p>
>
> <p>
> <js:link title="JavaScript function call..."
> onclick="alert('Booh!')">JavaScript call 1</js:link>
> </p>
>
> <p>
> <a href="http://www.microsoft.com/windows/ie/default.mspx">Microsoft
> Internet Explorer</a>
> </p>
>
> <p>
> <js:link title="JavaScript function call..." onclick="alert('Booh
> again!')">JavaScript call 2</js:link>
> </p>
>
> <p>
> <a href="http://browser.netscape.com/ns8/">Netscape Navigator</a>
> </p>
>
> <p>
> <js:link title="JavaScript function call..." onclick="alert('Booh
> again!')">JavaScript call 3</js:link>
> </p>
> </body>
> </html>


Just from a quick test, there is a DOM Level 2 method,
getElementsByTagNameNS(String namespaceURI, String localName). However,
this method is available in Firefox and not in IE. But, IE does have a
namespace collection, document.namespaces, in which you can iterate
through.

 
Reply With Quote
 
VK
Guest
Posts: n/a
 
      10-26-2005
Martin Honnen wrote:
> Does it help if you use an <?IMPORT> processing instruction
> <http://msdn.microsoft.com/library/default.asp?url=/workshop/author/dh...>
> to bind that prefix?


<?IMPORT...> seems useless w/o "implementation" attribute pointing to a
behavior source you want to import from. Anyway I tried <?IMPORT
namespace="js"> with no progress.


web.dev wrote:
> IE does have a namespace collection, document.namespaces,
> in which you can iterate through.


The only (and above it not documented) property of "namespace" related
to the internal content appeared to be "tagNames".
So this object seems to be for global namespace management
(switching/adding). Any way I tried to use
document.namespaces[i].tagNames which leads immediately to the script
error "Not implemented".

This error combined with Martin Honnen's tip may mean that you can
display but you cannot handle custom elements in IE w/o corresponding
DTD file properly written and included?

Something like:
<!DOCTYPE HTML PUBLIC "-//VK//DTD HTML X.XX//EN"
"http://www.geocities.com/schools_ring/js.dtd">
(The above is a joke and I *really* hope it will remain such).

This IE is a real Pandora box but we have to eat it somehow... But how?

 
Reply With Quote
 
Julian Turner
Guest
Posts: n/a
 
      10-27-2005

VK wrote:
> I have this code failing to work in IE: getElementsByTagName doesn't
> return elements from my JS namespace. What's wrong?
>
>
> <html xmlns:js>
> <head>
> <title>Que</title>
> <meta http-equiv="Content-Type" content="text/html;
> charset=iso-8859-1">
>
> <style type="text/css">
> <!--
> body { background-color: #FFFFFF}
> @media all {
> js\:link { font-style: italic; color: #0000FF; text-decoration:
> underline; cursor: hand; cursor: pointer}
> }
> -->
> </style>
>
> <script type="text/javascript">
> <!--
> function normalizeLinks(){
> var jsLink = document.getElementsByTagName('JS:LINK');
> // The method above doesn't work with IE
> // IE has some fancy twist I have to be reminded again
> for (i=0; i<jsLink.length; i++) {
> jsLink[i].title = '';
> jsLink[i].style.fontStyle = 'normal';
> }
> }
>
> if ('addEventListener' in self) {
> self.addEventListener('load',normalizeLinks,false) ;
> }
> else {
> self.attachEvent('onload',normalizeLinks);
> }
> //-->
> </script>
>
> </head>
>
> <body>
>
> <p>
> <a href="http://www.mozilla.org/products/firefox/">Mozilla Firefox</a>
> </p>
>
> <p>
> <js:link title="JavaScript function call..."
> onclick="alert('Booh!')">JavaScript call 1</js:link>
> </p>
>
> <p>
> <a href="http://www.microsoft.com/windows/ie/default.mspx">Microsoft
> Internet Explorer</a>
> </p>
>
> <p>
> <js:link title="JavaScript function call..." onclick="alert('Booh
> again!')">JavaScript call 2</js:link>
> </p>
>
> <p>
> <a href="http://browser.netscape.com/ns8/">Netscape Navigator</a>
> </p>
>
> <p>
> <js:link title="JavaScript function call..." onclick="alert('Booh
> again!')">JavaScript call 3</js:link>
> </p>
> </body>
> </html>


For IE specific solutions, I suggest that you delve more deeply into
the MSDN web site, and experiment a little:-

Two aspects which may help are:-

1. You can still use getElementsById("link").

This will return all "link" elements from all namespaces in the
document. As long as the local (i.e. RHS name) name is unique to a
given namespace (which I admit rather defeats the object of a
namespace), it can achieve what you are looking for.

2. If you need to filter the collection of "link" elements returned,
then you can use the "scopeName" property, introduced from IE5, which
will return the the namespace (i.e. LHS name) - namely "js".

Julian

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Custom Controls: Import a custom namespace and use its functions within user ASP .Net 1 07-19-2007 11:03 AM
ERROR CS0234: The type or namespace name 'DataAccessHelper' does not exist in the namespace 'BCC' (are you missing an assembly reference?) li.eddie@gmail.com ASP .Net 0 01-06-2006 11:31 AM
[XML Schema] Including a schema document with absent target namespace to a schema with specified target namespace Stanimir Stamenkov XML 3 04-25-2005 09:59 AM
Namespace: Is it a scope or a namespace? Anonymous C++ 3 08-18-2003 01:31 PM
Help:Why can't I use namespace System.Web? It is said that this namespace doesn't exist. But it should exist. ASP .Net 1 07-29-2003 04:31 PM



Advertisments