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

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

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
5 1842
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Web Webon | last post by:
Hi everybody! I wonder if this is possible? I need to determine if a client is using "windows classic folders" or anything else. If I instantiate a Shell ActiveX object is there a way of...
5
by: gsb | last post by:
I track the mouse location like this code: function mousePos(e) { var p = new Object(); if(e) { p.x = e.pageX; p.y = e.pageY; } else { p.x = event.x; p.y = event.y; } ... (show) }...
5
by: Amelyan | last post by:
How can I get state of dynamically created controls (RadioButton, CheckBox, TextBox.Text) on post back when I click submit button? The only way I know is by traversing Response.Form enumberator;...
3
by: Jordan | last post by:
I am dynamically inserting an html <input> tag as text (equivalent of an image button) into a page via a Literal control. Something like this gets inserted: <input type="image"...
1
by: vj | last post by:
How i can populate all fileds dynamically in jsp page based on contents found in xml file? I have written jsp servlets and java class file. i transferred automatic data from jsp to servlet then to...
0
by: vijendra | last post by:
How i can populate all fileds dynamically in jsp page based on contents found in xml file?I have written jsp servlets and java class file. i transferred automatic data from jsp to servlet then to...
7
by: petethebloke | last post by:
Can anyone help? I have a client who has made a "dynamic interactive map" of our city using Dreamweaver. Each map file has hotspots that pop-up a div with a little image when the mouse goes over...
9
by: Marky1124 | last post by:
Hi, I am hoping that someone can offer me some advise. I am new to CSS layouts and I've struggled to produce the screen layout that I wanted. Here's my demonstration page:- ...
1
by: sindhu | last post by:
Hello, I am able to attach event to dynamically created element.as shown below. for(var i=0;i<10;i++) {for(var j=0;j<15;j++) { var div=document.createElement('div'); ...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
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...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.