473,421 Members | 1,678 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,421 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 6682
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.