isDefaultNamespace method
9 | ||||
Returns whether the specified namespace URI is the default namespace in the scope of the current node.
Note: The isDefaultNamespace method of HTML elements and attributes is only supported in Firefox, Safari, Google Chrome and Internet Explorer from version 9.
The default namespace for HTML elements and attributes is an empty string in Firefox, and "http://www.w3.org/1999/xhtml" in Google Chrome, Safari and Internet Explorer.
In Opera, the isDefaultNamespace method always returns false on HTML elements and attributes.
Note: The isDefaultNamespace method is not supported in Internet Explorer in XML documents.
To get the namespace prefix that is associated with a namespace URI, use the lookupPrefix method.
To get the namespace URI that is associated with a namespace prefix, use the lookupNamespaceURI method.Syntax:
You can find the related objects in the Supported by objects section below.
Parameters:
Required. String that specifies the namespace URI to test. |
Return value:
Boolean. One of the following values:
The specified namespace URI is not the default namespace. | |
The specified namespace URI is the default namespace. |
Example HTML code 1:
This example illustrates the use of the isDefaultNamespace method:
|
|||||||
<head> <script type="text/javascript" src="ajax.js"></script> <script type="text/javascript"> var httpRequest = null; function SendRequest () { if (!httpRequest) { httpRequest = CreateHTTPRequestObject (); // defined in ajax.js } if (httpRequest) { // The requested file must be in the same domain that the page is served from. var url = "ns.xml"; httpRequest.open ("GET", url, true); // async httpRequest.onreadystatechange = OnStateChange; httpRequest.send (null); } } function OnStateChange () { if (httpRequest.readyState == 0 || httpRequest.readyState == 4) { if (IsRequestSuccessful (httpRequest)) { // defined in ajax.js TestDefaultNamespace (); } else { alert ("Operation failed."); } } } function TestDefaultNamespace () { var xmlDoc = ParseHTTPResponse (httpRequest); // defined in ajax.js if (!xmlDoc) return; var firstItem = xmlDoc.getElementsByTagName ("item")[0]; if (firstItem.isDefaultNamespace) { var isDef = firstItem.isDefaultNamespace ("http://help.dottoro.com/defaultNS"); alert ("Is the 'http://help.dottoro.com/defaultNS namespace the default?\n" + isDef); var isDef = firstItem.isDefaultNamespace ("http://help.dottoro.com/NS"); alert ("Is the 'http://help.dottoro.com/NS' namespace the default?\n" + isDef); } else { alert ("Your browser doesn't support the isDefaultNamespace method."); } } </script> </head> <body> <button onclick="SendRequest ()">Test the default namespace</button> </body> |
|||||||
|
|||||||
Did you find this example helpful?
|
Supported by objects:
attribute, CommentNode, document, DocumentFragment, TextNode, XMLDocument
HTML elements:
a, abbr, acronym, address, applet, area, b, base, basefont, bdo, bgsound, big, blink, blockquote, body, br, button, caption, center, cite, code, col, colgroup, comment, dd, del, dfn, dir, div, dl, dt, em, embed, fieldset, font, form, frame, frameset, h1, h2, h3, h4, h5, h6, head, hr, html, i, iframe, img, input:button, input:checkbox, input:file, input:hidden, input:image, input:password, input:radio, input:range, input:reset, input:search, input:submit, input:text, ins, isindex, kbd, keygen, label, legend, li, link, listing, map, marquee, menu, meta, nobr, noframes, noscript, object, ol, optgroup, option, p, param, plaintext, pre, q, rt, ruby, s, samp, script, select, small, span, strike, strong, style, sub, sup, table, tbody, td, textarea, tfoot, th, thead, title, tr, tt, u, ul, var, wbr, xml, xmp
Related pages:
External links:
User Contributed Comments