473,406 Members | 2,208 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,406 software developers and data experts.

Equivalent of Measurestring in javascript?

All;

As the subject implies, I'm wondering if there is anything resembling a
Javascript equivalent of a MeasureString method?

I am dynamically constructing a dialog box with a user-specified
message, and I might need to resize the box based on the length of the
message, but I've not found anything that might suggest how I can
determine the length of a string rendered in the current browser
window's font.

Thanks for any help.

-intrepid

Oct 24 '06 #1
2 3069
wrote on 24 okt 2006 in comp.lang.javascript:
As the subject implies, I'm wondering if there is anything resembling a
Javascript equivalent of a MeasureString method?
MeasureString method?

===================================

<span id='q'>zzz</span>

<script type='text/javascript'>
var q = document.getElementById('q')
s = 'the quick brown fox'
q.innerHTML = s
alert(q.offsetWidth)
s = 'the quick brown fox jumps over the'
q.innerHTML = s
alert(q.offsetWidth)
q.innerHTML = ''
alert(q.offsetWidth)
</script>

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Oct 24 '06 #2
Evertjan,

Thanks very much! I appreciate your effort.

-intrepid

Evertjan. wrote:
wrote on 24 okt 2006 in comp.lang.javascript:
As the subject implies, I'm wondering if there is anything resembling a
Javascript equivalent of a MeasureString method?

MeasureString method?

===================================

<span id='q'>zzz</span>

<script type='text/javascript'>
var q = document.getElementById('q')
s = 'the quick brown fox'
q.innerHTML = s
alert(q.offsetWidth)
s = 'the quick brown fox jumps over the'
q.innerHTML = s
alert(q.offsetWidth)
q.innerHTML = ''
alert(q.offsetWidth)
</script>

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Oct 25 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Alien | last post by:
Why does this code Console.WriteLine(g.MeasureString("a", new Font("Lucida Console", 11f)).Width); Console.WriteLine(g.MeasureString("aa", new Font("Lucida Console", 11f)).Width); produce...
1
by: Jesse Wade | last post by:
I'm trying to create a function that will pad a string with spaces so that the resulting string is a specific width (in this case 50points). As expected, the following code when passed an empty...
1
by: Yaron | last post by:
Hi, I made a procedure which receives a Graphics parameter, and with that Graphics parameter, performs various things. The area of confusion here is that when I pass the procedure a Graphics...
2
by: Stuart Norris | last post by:
Dear Group, I have a question about the result from ‘graphics.MeasureString' when using a mono-spaced font. Firstly I assume that Courier New font is mono-spaced, ie each character takes up the...
0
by: Meetali Goel | last post by:
Hi all, I can't determine why I keep getting "NotSupportedException" when g.MeasureString() is called in the following code (.NET CE). I have spent several hours but I cant seem to find the...
5
by: Marc | last post by:
I want to use Measurestring in a Class. In a form I write cInt(Me.CreateGraphics.Measurestring("Text", mFont).Width) What do I write in a class (I dont't have the Me.CreateGraphics there...) ...
7
by: teo | last post by:
Hallo, I'd like to retrieve the pixel length of a string. ------------------------ I decided to use MeasureString, but I have a problem with the graphic "instance" of it. I'm in a Sub and
2
by: teo | last post by:
I have to measure the length of a string in a Label, to set the adequate Label width (because not all browsers support the auto-size Label property). I decide to use the 'MeasureString'...
6
by: Rainer Queck | last post by:
Hello NG, I am trying to adjust the column width of a DataGridView to the Text in its column header. To do this I am using the Graphics.MeasureString method. Unfortunatly I alway get a too...
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: 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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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...
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...

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.