Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: Pixel length of strings (Javascript+DOM)

by LanX (Saint)
on Jul 11, 2009 at 21:18 UTC ( [id://779253]=note: print w/replies, xml ) Need Help??


in reply to Pixel length of strings

let's assume you can use a font which renders exactly the same in all browsers and is per default installed on all OSes...

You can use Javascript to determine the pixel length of this font!

E.g. by reading the coordinates of embracing links, this already worked with Netscape4-"DOM" and I used it this way to get font-width.

So just send a HTML-Page to your browser with the font and the JS and read out the results.

You can do it via a webserver and a form-submit (or AJAX's XmlHttpRequest) with the results or even by remotely telling a local Firefox to load and save the (enriched) local webpage (-remote option)

Cheers Rolf

UPDATE: Should even be possible to send the JS-Code via telnet to a MozRepl AddOn in FF.

NOTA BENE:This solution implies at least one running webbrowser, but gives you real control and testing over the resulting page.

UPDATE2: Well seems NS4 was also the last browser to support link-coordinates, but I'm sure that standard DOM has even much richer possibilities. ... indeed style.left, style.top or offsetLeft, offsetTop

  • Comment on Re: Pixel length of strings (Javascript+DOM)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://779253]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (5)
As of 2024-04-19 15:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found