473,383 Members | 1,855 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,383 software developers and data experts.

text works in IE, not in Firefox

Hi, first post here!

This function works great in IE (text shows up great), but in Firefox, it doesn't work (no text at all):
Expand|Select|Wrap|Line Numbers
  1. function AddText(text, x, y, color, size) {
  2.     labelCount++
  3.  
  4.     var position = $("canvas").position();
  5.     var CanvasX = x + position.left + document.documentElement.scrollLeft;
  6.     // -5 accounts for half the text height
  7.     var CanvasY = y + position.top + document.documentElement.scrollTop - 5;
  8.  
  9.     var label = document.createElement("div");
  10.     label.id = "label" + labelCount;
  11.     label.style.position = "absolute";
  12.     label.style.left = CanvasX;
  13.     label.style.top = CanvasY;
  14.     label.style.fontFamily = "sans-serif";
  15.     label.style.fontSize = size;
  16.     label.style.color = color;
  17.     label.appendChild(document.createTextNode(text));
  18.     document.body.appendChild(label);
  19. }
  20.  
Any thoughts or suggestions are appreciated.

Thanks!

Using IE8 and FF 3.6.13
Feb 21 '11 #1
2 1362
BTW, this function was adapted from page 560 of the book Javascript The Definitive Guide Fifth Edition.

The answer to the issue is that I left out + "px", so
Expand|Select|Wrap|Line Numbers
  1. label.style.left = CanvasX + "px";
  2. label.style.top = CanvasY + "px";
Now, everything works fine in IE and FF.
Feb 21 '11 #2
acoder
16,027 Expert Mod 8TB
Thanks for posting the solution (not many come back to do that).

Just a quick point: I wouldn't use IE as my starting point for testing anything if I want an application/website to work cross-browser.
Feb 23 '11 #3

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

Similar topics

16
by: C.W | last post by:
I have a top box element that houses the web site title: #top_section { height: 20px; padding: 10px; text-align: left; background: navy; color: white; }
2
by: anna | last post by:
Firefox Mozilla Browser Fonts / Format / rich text / webmail question I have Comcast. They do not support Firefox so they won't help me. When I use Mozilla firefox browser to access my web...
5
by: Randell D. | last post by:
Folks, I have a few <INPUT TYPE=TEXT> tags that are readonly if a specific field has no value... these work fine. However, I also have checkboxes which I would like to have as readonly, but the...
4
by: leodippolito | last post by:
Hello sirs, I am trying to send a POST request to a webservice on the click of a button. This will return me an XML document with a list of combo box items. The problem: in FIREFOX, when the...
10
by: andreister | last post by:
He there! I've discovered that the ================================================= document.links('link_id_here').href = "something"; ================================================= is...
4
by: drew197 | last post by:
I am a newbie. I am editing someone elses code to make it compatible with Firefox and Safari. In IE, when you click on the proper link, a block of text is shown in a nice paragraph form. But, in...
4
by: Dan Pearce | last post by:
Processing some text from an external text file into a web page. If I use this: <? $s = file_get_contents('text.txt'); $search = array("@\r\n@si"); $replace = array('</br>'); echo...
1
by: gferreri | last post by:
Hi all, I've stumbled on an interesting problem with the way Firefox handles form submitting with the enter key. I'm putting together a page that has one form element with multiple controls...
1
by: Maxime | last post by:
Hello, I want to make a button that automatically resizes according to the text length and the font size (which can be changed in firefox pretty easily with the browser). The button already...
8
rblaettler
by: rblaettler | last post by:
I have two div's with a float:left attribute that I've put into a list. They should align horizontally, which they do as long as the text in them does not need to be wrapped. As soon as the area for...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: 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
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...

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.