innerText/textContent equivalent for IE8 beta?, need some pointers... |
innerText/textContent equivalent for IE8 beta?, need some pointers... |
TrojanNemo |
Dec 28 2008, 12:39 AM
Post
#1
|
Group: Members Posts: 6 Joined: 27-May 08 From: Miami, Florida Member No.: 5,757 |
hey guys.
after much reworking of my contact page (from a static .htm to a .aspx with captcha, vbscript and a crapload of javascript), now i'm stuck at what seems like it would be a simple thing. this is my current code: CODE if (document.all){ if (vLabel.innerText == "Validation succeeded. Thank you."){ ChangeButtons();} } else{ if (vLabel.textContent == "Validation succeeded. Thank you."){ ChangeButtons();} } } that works in Internet Explorer 7.0.5730.13, Mozilla Firefox 3.0.5, Flock 1.2.7, Google Chrome 1.0.154.36, Opera 9.63, and Apple Safari 3.1.2. (haven't tried Netscape yet) my issue is with Internet Explorer 8 Beta 2. according to Microsoft, IE8 no longer supports dynamic properties while running in IE8 mode, so all my work went down the drain like that. what can I use in place of innerText and textContent that will work in Internet Explorer 8 and newer? is there a all-in-one solution that will/should work in ALL browsers? thanks a ton! |
TrojanNemo |
Dec 28 2008, 02:41 AM
Post
#2
|
Group: Members Posts: 6 Joined: 27-May 08 From: Miami, Florida Member No.: 5,757 |
code verified working in Netscape Navigator 9.0.0.6 and Internet Explorer 8 Beta 2
if my first post still makes sense and you have a suggestion, please post it. for some reason IE8 Beta 2 still worked fine (i guess using .textContent) on my XP Pro computer...i'll have to see what's going on with my fiancee's laptop...it might be a local issue rather than a code problem |
Christian J |
Dec 29 2008, 04:47 PM
Post
#3
|
. Group: WDG Moderators Posts: 9,653 Joined: 10-August 06 Member No.: 7 |
QUOTE if (document.all) document.all is not a reliable way to identify MSIE, since other browsers may support it too. The proper way is to check the actual object you are going to use, as outlined on http://www.quirksmode.org/js/support.html In this case you might use: CODE if(document.body.textContent) { // use textContent here } else if(document.body.innerText) { // use innerText here } however that will not cover various older browser versions (maybe not all current ones either), so some kind of fallback wouldn't hurt. You should also provide a fallback for browsers without javascript (perhaps using the NOSCRIPT element) or without image viewing (with image ALT text). QUOTE IE8 no longer supports dynamic properties AFAIK, innerText is not a dynamic property. Dynamic properties are used to add scripting in style sheets. QUOTE what can I use in place of innerText and textContent that will work in Internet Explorer 8 and newer? is there a all-in-one solution that will/should work in ALL browsers? If the element contains plain text only (i.e. no HTML tags) you can use innerHTML in most (all?) modern browsers. Otherwise you can search for text nodes among the element nodes (and concatenate their nodeValues if necessary). See http://www.quirksmode.org/dom/w3c_core.html This post has been edited by Christian J: Dec 29 2008, 08:10 PM |
Lo-Fi Version | Time is now: 19th April 2024 - 03:25 PM |