开发者

How To Get The Width in px of an HTML div in Perl

I have a bunch of HTML divs of the format:

<div style="left:162;vertical-align:top;color:#000000;top:126;position:absolute;font-family:Times;font-size:14;">
     BLAH BLAH BLAH
</div>
开发者_如何学C

What I'd like to do is extract from that div the expected width of the text. I know I can do this in Javascript with stuff like obj.offsetWidth(), and was wondering if there's any similar CPAN module that can do that for Perl, or if anyone has any ideas on algorithms I can code that will give me the information I need. I feel like all the information necessary for calculating what the width ought to be is contained in the style tag, so this should be doable.

Thanks!

[EDIT] Adding a bit more background to my question, what I really want to do is take an HTML page that's passed to my module offline, and resize that HTML so that its width does not exceed 800px in most-to-all standard browser configurations. The HTML I'm passed is entirely made up of divs with absolute position, so I figured if I could make a reasonable low-ball guess about the width of each div, I'd know approximately by what factor I'd need to make each one's font size smaller. [/EDIT]


Perl typically runs on the server, not in the browser, and the information you seek is not directly accessible from the server in any language. If you really need that information on the server (and I can't easily imagine any scenario where you would...), you'll have to send some JavaScript to the client, which would obtain the info and send it back to the server, probably via AJAX.


none of your numeric properties are valid; all require specification of units; for example:

<div style="left:162px;vertical-align:top;color:#000000;top:1.26in;position:absolute;font-family:Times;font-size:14pt;">

Better, specify the font size and top:property (top: 1.26em) in ems (font-size: 1.4em;) as use of absolute units is deprecated.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜