以像素为单位获取整个页面的高度

Get the height of a whole page in pixel

本文关键字:高度 像素 为单位 获取      更新时间:2023-09-26

对于某些装饰,我需要在文档的开头插入一个上边距,占页面整个高度的34%(包括边距)。
我的页面<正文>像这样开始:

    <body bgcolor="#dedede" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" style="-webkit-text-size-adjust:none;">
        <tbody>
            <table width="100%" border="0" cellpadding="0" cellspacing="0" align="center" bgcolor="#dedede">
                <tr>
                    <td>
                        <table class="premier-tableau" width="600" bgcolor="#ffffff" border="0" cellpadding="0" cellspacing="0" align="center">
                        <thead>
                                <tr height="500" /> <!-- I need to use this line as a margin -->
                        </thead>
                        <tbody>
                            <tr>
                                <td width="35" />
                                <td width="530">
                                    <font color="#5e5e5e" face="Arial, Helvetica, sans-serif" size="2" style="font-size: 12px;">

这用于电子邮件。

当然,可以手动计算像素数,并将静态结果添加到

标签中。但是,这是半自动化过程的一部分,我想避免这种情况。
另请注意,目标 SMTP 服务器可能具有严格的策略并拒绝附件。所以,我不明白如何使用外部库(如JQuery)。由于可以使用现代 ecmascript,我想避免使用它们......

任何可嵌入的解决方案(css;javascript;svg ...)都被接受。

document.body.parentNode.offsetHeight但是 - JavaScript不会在电子邮件中运行:)因此,我认为您需要手动执行此操作。

由于您的身体没有边距,因此应该使用简单的高度。

document.getElementsByTagName("body")[0].height

有为此设计的视口单元。实际上很少有浏览器支持它,但使用height="34vh"将是某些年份的正确方法。

客户需要几年时间才能遵守该标准。现在继续的一种实际方法是在每次编辑文档时手动计算大小(以 px 为单位)。