473,387 Members | 3,821 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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 6681
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

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

Similar topics

15
by: Dan | last post by:
Hi. I've got the following line of code which works fine in IE ... line_1_numbers = document.getElementsByTagName ('table').rows (0).cells (0).innerText; But it Firefox, it barks saying: ...
4
by: millw0rm | last post by:
Hi wats wrng with this code??? it works fine on IE6 but not on FireFox 1.5??? var anOption = document.createElement("OPTION"); document.getElementById("category").options.add(anOption);...
7
by: Hoss | last post by:
Hello all- This is what im trying to achieve. At the top of my page there is some search functionality, through which you cause to be loaded a string representing an HTML page. Below this and...
3
by: Bruno Alexandre | last post by:
Hi guys, I'm performing a form validation using the javascript in the ASPX pages and I got into a part that I can't figure it out how to move foward. All is resumed in this page: ...
20
by: effendi | last post by:
I am testting the following code in firefox function fDHTMLPopulateFields(displayValuesArray, displayOrderArray) { var i, currentElement, displayFieldID, currentChild, nDisplayValues =...
3
by: Alexander Higgins | last post by:
Hello, I would like to thank everyone for there help in advance. I have form which is using an iframe as a Rich Text Editor. Everything works as expected in IE but I have two issues with...
3
by: Jake G | last post by:
Ok. I have figured out my whole script except how to make it work in FF. It is a script that lets a user know how many characters they have left for a textbox. Here is the code, is anyone savy...
3
by: fulio pen | last post by:
Hello, I have a code that works on both the IE and Opera, but not the Firefox, and I cannot figure out the reason. Following is the page: http://www.pinyinology.com/test/span2.html And...
1
by: xtremebass | last post by:
Hello Bytes, i have a calender program which is created by using Javascript. when i execute that program using Internet Explorer,it works properly but when i tried in Mozilla firefox it didnt...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.