Bug Tracker

Modify

Ticket #6827 (closed bug: wontfix)

Opened 4 years ago

Last modified 3 years ago

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:
Blocking: Blocked by:

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

test.html Download (302 bytes) - added by WouterTinus 4 years ago.
Testcase

Change History

Changed 4 years ago by WouterTinus

Testcase

comment:1 Changed 4 years ago by dmethvin

  • Summary changed from Inconsistant behaviour in .text() to Inconsistent behaviour in .text() on script elements

comment:2 Changed 4 years ago by WouterTinus

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 );

}

comment:3 Changed 4 years ago by WouterTinus

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)

comment:4 Changed 4 years ago by snover

  • Priority set to undecided
  • Status changed from new to closed
  • Resolution set to wontfix

Use .html.

comment:5 Changed 3 years ago by jitter

#7923 is a duplicate of this ticket.

Please follow the  bug reporting guidlines and use  jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

View

Add a comment

Modify Ticket

Action
as closed
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.