Click here to Skip to main content
15,072,051 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I always believe Firefox is a worse browser than chrome for javascript.The two code is fired in chrome,but not in firefox-----------

1."
JavaScript
alert(document.getElementById('ctl00_ContentPlaceHolder1_listprice').innerText)
"
>This alerts "Undefined" in firefox but the innertext is alerting perfect result in chrome.So how to write the code for firefox?
Note:"listprice" is a
.

2.I have created image in runtime and added the code:
C#
img.Attributes.Add("onmousemove", "javascript:movediv('imageShow','event')");

"imageShow" is the id of the div which will be moved on moving mouse over the image.

javascript code:

JavaScript
function movediv(element,e)
{
var v=document.getElementById(element);
v.style.top=parseInt(window.event.clientY.toString())-180+'px';
v.style.left=parseInt(window.event.clientX.toString())-250+'px';

v.style.borderRadius='8px';
v.style.align='center';
}

this works in chrome,but not in firefox.How to write this for firefox?Please help.
Posted
Updated 13-Aug-12 23:07pm
v3

Try this
JavaScript
alert(document.getElementById('ctl00_ContentPlaceHolder1_listprice').innerHtml)

or
JavaScript
alert(document.getElementById('ctl00_ContentPlaceHolder1_listprice').textContent)
   
Comments
souvikcode 15-Aug-12 12:22pm
   
this helps.good.
souvikcode 15-Aug-12 12:44pm
   
In which chrome differ from Mozilla?appCodeName and appName is same for these two browsers,so how to get difference between them?
pradiprenushe 16-Aug-12 0:59am
   
You can do like this
if(document.getElementById('ctl00_ContentPlaceHolder1_listprice').innerText != undefined)
{
alert(document.getElementById('ctl00_ContentPlaceHolder1_listprice').innerText);
}
else if(document.getElementById('ctl00_ContentPlaceHolder1_listprice').innerHtml!= undefined)
{
alert(document.getElementById('ctl00_ContentPlaceHolder1_listprice').innerHtml);
}
else if(document.getElementById('ctl00_ContentPlaceHolder1_listprice').textContent!= undefined)
{
alert(document.getElementById('ctl00_ContentPlaceHolder1_listprice').textContent);
}
I find firefox javascript errors much easier to resolve than the dreaded IE 'Guess where the error occured' style of debugging but since it works in chrome we can safely assume FF is the problem.

If I look at :
C#
function movediv(element,e)
{
var v=document.getElementById(element);


The position of where you place your script may be the problem.
For instance with scripts like these I usually prefer to place my script tagas right under

Hope this helps

also as a tip
JavaScript
<script type="text/JScript"> </script>
will only work on certain browsers type="text/javascript" for the win (not sure if this could be the issue

also check your source and ensure that a control with name 'imageShow' actually exists , it its a server control you might have to use the ClientID to get the valid javascript ID.
   
v2
Comments
souvikcode 15-Aug-12 12:21pm
   
Please Submit perfect answer.
L Viljoen 16-Aug-12 6:15am
   
for a perfect answer I need the source of what is causing the issue , as in the whole document , I gave you answers based on what could be causing the issue in firefox, I dont have your document so I have to guess what the issue is.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900