By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,362 Members | 3,489 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,362 IT Pros & Developers. It's quick & easy.

Determine dynamically how far from the left of the Client area an element is?

P: n/a
Say I have this in a web page:

<center><a href="http://www.microsoft.com">www.microsoft.com</a></center>

I can use CSS, the DOM and\or JavaScript to determine the width style.innerHTML.length of the www.micosoft.com. But how can I tell in pixels how far it is from the left side of the client area using JavaScript? If the browser is resized and the text wraps the distance will change. So I need to determine it dynamically. Thanks.

--
George Hester
__________________________________
Jul 20 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
George Hester wrote:
<center><a
href="http://www.microsoft.com">www.microsoft.com</a></center>
Do not use the `center' element, it is deprecated. Use the
`p' or `div' element and CSS' `text-align:center' instead.
I can use CSS, the DOM and\or JavaScript to determine the width
style.innerHTML.length of the www.micosoft.com. But how can I tell
in pixels how far it is from the left side of the client area using
JavaScript?
Use the DOM either. IE provides the `offsetLeft' property
while with standards-compliant UAs like Mozilla you can use
the getComputedStyle(...) method. Questions like this were
asked a few times, especially in the last days. Please
search/read *before* you post.
If the browser is resized and the text wraps the distance will change.
What's the problem?
So I need to determine it dynamically.


You only need working markup. What if JavaScript is disabled or not
supported? What if the DOM of the UA does not allow for reading the
computed coordinates? (X)HTML is not designed to be a layout language
or format like PDF. That the text flow adjusts automatically to the
client area instead of scaling the content to its size is its major
advantages, and you cannot fix design flaws in Web documents with
JavaScript reliably.
PointedEars
Jul 20 '05 #2

P: n/a
Thomas unfortunately I can only use what I have. When I made the site I used <center>. Yes I know I shouldn't have but now that I have that is what I have. And if I can work around that with an idea that would be much easier then going through the site which is pretty large and changing all the center tags. That would be a lot of work. See that is why we aren't suppose to use it. I know. But I have and that is what I have.

Well I hope in your following text you have a suggestion on how to do what I want to do. Because that basically is what I am asking. I don't care if some browsers cannot support it. I don't care if it follows the rules. I don't care about anything else other then a suggestion how to do what I asked to do. If the answer is "you cannot" with what I have provided then that is fine. Say so.

--
George Hester
__________________________________
"Thomas 'PointedEars' Lahn" <Po*********@web.de> wrote in message news:3F**************@PointedEars.de...
George Hester wrote:
<center><a
href="http://www.microsoft.com">www.microsoft.com</a></center>


Do not use the `center' element, it is deprecated. Use the
`p' or `div' element and CSS' `text-align:center' instead.
I can use CSS, the DOM and\or JavaScript to determine the width
style.innerHTML.length of the www.micosoft.com. But how can I tell
in pixels how far it is from the left side of the client area using
JavaScript?


Use the DOM either. IE provides the `offsetLeft' property
while with standards-compliant UAs like Mozilla you can use
the getComputedStyle(...) method. Questions like this were
asked a few times, especially in the last days. Please
search/read *before* you post.
If the browser is resized and the text wraps the distance will change.


What's the problem?
So I need to determine it dynamically.


You only need working markup. What if JavaScript is disabled or not
supported? What if the DOM of the UA does not allow for reading the
computed coordinates? (X)HTML is not designed to be a layout language
or format like PDF. That the text flow adjusts automatically to the
client area instead of scaling the content to its size is its major
advantages, and you cannot fix design flaws in Web documents with
JavaScript reliably.


PointedEars

Jul 20 '05 #3

P: n/a
Thanks you gave me what I asked for. offsetLeft does it perfectly.

--
George Hester
__________________________________
"Thomas 'PointedEars' Lahn" <Po*********@web.de> wrote in message news:3F**************@PointedEars.de...
George Hester wrote:
<center><a
href="http://www.microsoft.com">www.microsoft.com</a></center>


Do not use the `center' element, it is deprecated. Use the
`p' or `div' element and CSS' `text-align:center' instead.
I can use CSS, the DOM and\or JavaScript to determine the width
style.innerHTML.length of the www.micosoft.com. But how can I tell
in pixels how far it is from the left side of the client area using
JavaScript?


Use the DOM either. IE provides the `offsetLeft' property
while with standards-compliant UAs like Mozilla you can use
the getComputedStyle(...) method. Questions like this were
asked a few times, especially in the last days. Please
search/read *before* you post.
If the browser is resized and the text wraps the distance will change.


What's the problem?
So I need to determine it dynamically.


You only need working markup. What if JavaScript is disabled or not
supported? What if the DOM of the UA does not allow for reading the
computed coordinates? (X)HTML is not designed to be a layout language
or format like PDF. That the text flow adjusts automatically to the
client area instead of scaling the content to its size is its major
advantages, and you cannot fix design flaws in Web documents with
JavaScript reliably.


PointedEars

Jul 20 '05 #4

P: n/a
What did I do wrong to deserve such a posting?

George Hester wrote:
Thomas unfortunately I can only use what I have. When I made the
site I used <center>. Yes I know I shouldn't have but now that I
have that is what I have.
So bad design in the past justifies bad design in the future?
And if I can work around that with an idea that would be much easier
then going through the site which is pretty large and changing all
the center tags. That would be a lot of work.
Sure it will but it will pay off. You can take that literally if you
run a commercial web site.
See that is why we aren't suppose to use it. I know. But I have and
that is what I have.
See above.
Well I hope in your following text you have a suggestion on how to do
what I want to do.
I already did.
Because that basically is what I am asking. I don't care if some
browsers cannot support it. I don't care if it follows the rules.


So if you do not care for your visitors, what the heck do you then want
on the Web -- posing yourselves? I will not support you in doing that.
Go away, now.
PointedEars
Jul 20 '05 #5

P: n/a
Thomas you gave the answer offsetLeft. That did what I wanted. If you had posted "offsetLeft" and nothing else you would have provided what I asked for. But you chose to provide an opinion on what I wanted to do pointing out where I was wrong for asking what I asked. I'll go away and I hope you do too. I do not need this crap.

--
George Hester
__________________________________
"Thomas 'PointedEars' Lahn" <Po*********@web.de> wrote in message news:3F**************@PointedEars.de...
What did I do wrong to deserve such a posting?

George Hester wrote:
Thomas unfortunately I can only use what I have. When I made the
site I used <center>. Yes I know I shouldn't have but now that I
have that is what I have.


So bad design in the past justifies bad design in the future?
And if I can work around that with an idea that would be much easier
then going through the site which is pretty large and changing all
the center tags. That would be a lot of work.


Sure it will but it will pay off. You can take that literally if you
run a commercial web site.
See that is why we aren't suppose to use it. I know. But I have and
that is what I have.


See above.
Well I hope in your following text you have a suggestion on how to do
what I want to do.


I already did.
Because that basically is what I am asking. I don't care if some
browsers cannot support it. I don't care if it follows the rules.


So if you do not care for your visitors, what the heck do you then want
on the Web -- posing yourselves? I will not support you in doing that.
Go away, now.


PointedEars

Jul 20 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.