Side navigation
#6827 closed bug (wontfix)
Opened July 26, 2010 08:46AM UTC
Closed October 19, 2010 01:01AM UTC
Last modified January 08, 2011 01:41AM UTC
Inconsistent behaviour in .text() on script elements
Reported by: | WouterTinus | Owned by: | |
---|---|---|---|
Priority: | undecided | Milestone: | 1.4.3 |
Component: | core | Version: | 1.4.2 |
Keywords: | text, IE8 | Cc: | |
Blocked by: | Blocking: |
Description
When the .text() function is called on a script element, IE8 returns an empty string ''. Firefox, Opera and Chrome (latest versions) do however return the content. IE8 has no problem accessing the desired output through its .innerHTML property.
(Reason for filing this bug: we are using <script type="text/html"> tags to hide our rendering templates from the likes of the W3C validator and Google).
Attachments (1)
Change History (5)
Changed July 28, 2010 02:57AM UTC by comment:1
summary: | Inconsistant behaviour in .text() → Inconsistent behaviour in .text() on script elements |
---|
Changed July 29, 2010 07:57PM UTC by comment:2
The problem seems to be that while other browsers report a text node as child of <script>, the DOM implementation of IE does not. Here's a rough patch for the problem, starting from line 3436, that should at least work for IE8, FF3.6 and Chrome. Haven't tested other browsers.
Get the text from text nodes and CDATA nodes
if ( elem.nodeType === 3 || elem.nodeType === 4 ) {
ret += elem.nodeValue;
Special case for script nodes
} else if ( elem.tagName === 'SCRIPT' ) {
ret += elem.text;
}
// Traverse everything else, except comment nodes
} else if ( elem.nodeType !== 8 ) {
ret += getText( elem.childNodes );
}
Changed July 29, 2010 08:11PM UTC by comment:3
Actually there is several things you can return instead of elem.text:
- '' (in case you consider IE8 behavior correct)
- elem.text
- elem.innerHTML
But not:
- elem.innerText (undefined in FF, '' in IE8)
- elem.textContent (undefined in IE8)
- elem.nodeValue (null in IE8)
Changed October 19, 2010 01:01AM UTC by comment:4
priority: | → undecided |
---|---|
resolution: | → wontfix |
status: | new → closed |
Use .html
.