【发布时间】:2019-03-09 00:20:46
【问题描述】:
在我的反应应用程序中,我有一个iframe,它加载了 HTML 文档,其内容超过了 1 页。按Ctrl+p我想分几页打印,但打印预览只显示一页。
识别iframe的内容不止一个A4页面应该如何处理?
chrome devtool 中的 DOM 看起来像
<div class="article-container">
<iframe style="">#document
/* hundreds of <p> tags */
</iframe>
</div>
react 应用中的结构是这样的
<div className="article-container">
<FrameText content={content} status={!this.state.editStatus} />
</div>
和 FrameText
class FrameText extends React.Component<Props> {
iframe: HTMLIFrameElement;
compinentDidMount(){
window.addEventListener('beforeprint',(e)=>{console.log(e);})
}
/* other stuff*/
render() {
const { status } = this.props;
return <iframe ref={(ref) => (this.iframe = ref!)} style={!status ? { display: 'none' } : {}} />;
}
因此,当按下ctrl+p 时,我得到了事件,并且 iframe 文档在事件中。另外,我在当地也有 iframe 的内容。
我找不到任何地方,当触发此事件时,我可以用它做什么来操纵或以某种方式告诉打印预览内容很长。
另外,css是
@media print {
.article-container {
background-color: white;
height: 100%;
width: 100%;
position: fixed;
top: 0;
left: 0;
margin: 0;
padding: 15px;
font-size: 14px;
line-height: 18px;
}
}
【问题讨论】:
-
有点脏但可能就足够了:如果您知道大约页数,您可以估计 iFrame 必须以像素为单位的高度,并将其设置在 print-css 中,例如 4000px 或东西。
标签: javascript iframe media-queries dom-events printing-web-page