469,336 Members | 6,245 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,336 developers. It's quick & easy.

firefox IE different, innerText question

130 100+
hello all,

i got this code that works fine in IE but not in FF

Expand|Select|Wrap|Line Numbers
  1. code = obj.innerHTML;
  2. document.getElementById('pre').innerText = code; 
i can make it work in FF like shown here on section 9
my qustion is

how and when shouled i check for the broswer?
shouled i use try...catch ? (cuz FF dont show error it just ignor that innerText)

thanks alot
Nov 13 '07 #1
11 6341
gits
5,390 Expert Mod 4TB
hi ...

for that purpose you shouldn't detect a browser ... you may simply use innerHTML instead of innerText for all browsers ...

kind regards
Nov 13 '07 #2
Dasty
101 Expert 100+
FF got textContent property instead :D
This function should be sufficient ...

Expand|Select|Wrap|Line Numbers
  1. function setInnerText(obj, text)
  2. {
  3.   if (obj.innerText)
  4.   {
  5.     obj.innerText = text;
  6.   }
  7.   else
  8.   {
  9.     obj.textContent = text;
  10.   }
  11. }
  12.  
Nov 13 '07 #3
Amzul
130 100+
thanks for the fast replays guys

GITS-
if i will use innerHTML it will display the code or will execute it ?
i need to see the code the user should see the code not execute it :)

DASTY-
why php?
is it going to work in javascript as well?
Nov 13 '07 #4
Dasty
101 Expert 100+
thanks for the fast replays guys

GITS-
if i will use innerHTML it will display the code or will execute it ?
i need to see the code the user should see the code not execute it :)

DASTY-
why php?
is it going to work in javascript as well?
It's javascript ofc. I am just not familiar with this forum yet :D
Nov 13 '07 #5
gits
5,390 Expert Mod 4TB
hi ...

i fixed the code tags above - it IS javascript ... and of course ... using innerHTML has the drawback you noticed. so use dasty's code or consider to use standards compliant dom methods with creating textNodes and appending them to the node you want ... have a look at the:

createTextNode();
appendChild();

dom-methods.

kind regards
Nov 13 '07 #6
iam_clint
1,208 Expert 1GB
innerTEXT or innerHTML


either of these will work for IE and firefox just gotta watch your case sensitivity.
Nov 13 '07 #7
acoder
16,027 Expert Mod 8TB
innerTEXT or innerHTML


either of these will work for IE and firefox just gotta watch your case sensitivity.
innerTEXT should be innerText and it doesn't work in Firefox (latest version).

Another option besides textContent is firstChild.data (check for whitespace first).
Nov 14 '07 #8
Amzul
130 100+
FF got textContent property instead :D
This function should be sufficient ...

Expand|Select|Wrap|Line Numbers
  1. function setInnerText(obj, text)
  2. {
  3.   if (obj.innerText)
  4.   {
  5.     obj.innerText = text;
  6.   }
  7.   else
  8.   {
  9.     obj.textContent = text;
  10.   }
  11. }
  12.  
sorry for bumping the therd up but from some reson its not working for me
but this does so....

Expand|Select|Wrap|Line Numbers
  1. function setInnerText(obj, text)
  2. {
  3.   if (navigator.appName =="Microsoft Internet Explorer")
  4.   {
  5.     obj.innerText = text;
  6.   }
  7.   else
  8.   {
  9.     obj.textContent = text;
  10.   }
  11. }
  12.  
Nov 19 '07 #9
acoder
16,027 Expert Mod 8TB
Don't use browser detection. Try this instead:
Expand|Select|Wrap|Line Numbers
  1. function setInnerText(obj, text)
  2. {
  3.   if (obj.textContent)
  4.   {
  5.     obj.textContent = text;
  6.   }
  7.   else if (obj.innerText)
  8.   {
  9.     obj.innerText = text;
  10.   }
  11. }
  12.  
Nov 19 '07 #10
Amzul
130 100+
so u saying innerText dont return false?

why checking the the broswer is a bad thing?
Nov 19 '07 #11
gits
5,390 Expert Mod 4TB
...
why checking the the broswer is a bad thing?
hi ...

you may read about it here :)

kind regards
Nov 19 '07 #12

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

15 posts views Thread by Dan | last post: by
4 posts views Thread by millw0rm | last post: by
3 posts views Thread by Bruno Alexandre | last post: by
3 posts views Thread by Alexander Higgins | last post: by
3 posts views Thread by Jake G | last post: by
3 posts views Thread by fulio pen | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by Marylou17 | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.