设置Div的left后,打印内容缩小很多?

yuanw 2008-02-28 12:30:35
有2个简单的html文件

tmp.htm

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>Untitled Page</title>
<style>
#divDetail {
border: solid 1px black;
width: 750px;
height: 520px;
position: absolute;
top: 55px;
z-index: 20;
}

</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<div id="divDetail">
<iframe id="ifrdetail" name="ifrdetail" frameborder="0" height="100%" width="100%"></iframe>
</div>
</div>
<script language="javascript">
document.getElementById("ifrdetail").src="tmp1.htm";

</script>
</form>
</body>
</html>


tmp1.htm

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<table cellpadding=0 cellspacing=0 border=1 width=650>
<tr>
<td>fsdgsdsd</td>
<td>
fsdgsdsd</td>
</tr>
<tr>
<td>
fsdgsdsd</td>
<td>
fsdgsdsd</td>
</tr>
<tr>
<td>
fsdgsdsd</td>
<td>
fsdgsdsd</td>
</tr>
</table>
<button onclick="document.focus();window.print()"> Print </button>
</div>
</form>
</body>
</html>


当单独显示tmp1.htm并打印,表格宽度刚好一页纸的宽度. 但当用tmp.htm调用tmp1.htm并点打印按钮,打印出的表格只有原来的一半左右. 我花了不少时间发现,当把tmp.htm里的divDetail的css中left:200px;这句删除掉再打印就基本正常(虽然还会缩小一点点,但不明显了).

我用的是xp和ie7,缺省配置.现在这个问题把我难住了,想不明白为何设置div的left会造成缩小,求教.谢谢
...全文
269 22 打赏 收藏 转发到动态 举报
写回复
用AI写文章
22 条回复
切换为时间正序
请发表友善的回复…
发表回复
yuanw 2008-05-10
  • 打赏
  • 举报
回复
microsoft论坛里面的专家回复了,他说是left属性导致计算里面的控件时出错.只要用css将div的left属性设为显示用,打印就不设这个.
meiZiNick 2008-05-01
  • 打赏
  • 举报
回复
有问题请先GOOGLE,BAIDU
knowledge_Is_Life 2008-04-30
  • 打赏
  • 举报
回复
我也想知道,正在找這方面的資料~~~~~
  • 打赏
  • 举报
回复
我试过是可以的
不知道你怎么做了!
yuanw 2008-03-03
  • 打赏
  • 举报
回复
这个方法我是试过的,没任何变化
  • 打赏
  • 举报
回复
<input type=button onclick="window.frames[ifrdetail].focus();window.frames[ifrdetail].print()">

放在父窗口也应该是没问题的
  • 打赏
  • 举报
回复
那是肯定的啊

button在tmp1里面那肯定不就行了

只能是新建窗口


因为你直接打印的不单是TMP1的,而是TMP
yuanw 2008-03-01
  • 打赏
  • 举报
回复
改成这个
<input type=button onclick="window.frames[ifrdetail].focus();window.frames[ifrdetail].print()">
是不行的,因为这个button在tmp1里面,打印的是当前页面,tmp1页面并不包含一个frame.

上一个例子是开新的window就不存在我这个奇怪的问题,用showModalDialog也一样正常.
  • 打赏
  • 举报
回复
要不你这个<button onclick="document.focus();window.print()"> Print </button>

改下来试下

改成:

<input type=button onclick="window.frames[ifrdetail].focus();window.frames[ifrdetail].print()">
  • 打赏
  • 举报
回复
给你一个具体的例子吧

<body>
<input onclick='prn()' type=button value=print_Iframe><br>
<iframe id=mxh src="d:\hhh.htm"></iframe>
<script>
function prn()
{
var win=window.open("about:blank")
win.moveTo(1200,1200)
win.location=document.all.mxh.src
win.print()
}
</script>
  • 打赏
  • 举报
回复
document.all.ifrdetail.print()
用这个来打印看看
  • 打赏
  • 举报
回复
你用JS控制打印的只是TMP1的内容就OK了!你直接打印的不单是TMP1的
yuanw 2008-02-29
  • 打赏
  • 举报
回复
怎么可能是打印tmp页呢?打印出来的就只是tmp1的内容,而tmp1里面的table也是靠左的,并没有一点tmp页面的东西.
而且我发现,当left的值设得越大,打印出的就会缩得越小,不设left,改用right就不会造成缩小,超级奇怪.

或者chinmo大侠给点代码看如何实现你的观点?
  • 打赏
  • 举报
回复
晕,把握的搞蒙了


我原来说的那意思是没错的


因为你打印的并不是tmp1.htm
而是包含它的页tmp.htm
你这样设置的话,那么他把那200也算进去了,所以你既然小,你要只打印tmp1.htm的那你还得用JS控制


这个意思是没错的


你现在的设置打印并不是打印的tmp1.htm,而是他的包含它的页tmp.htm
  • 打赏
  • 举报
回复
因为你打印的并不是tmp.htm
而是包含它的页tmp1.htm
你这样设置的话,那么他把那200也算进去了,所以你既然小,你要只打印tmp1.htm的那你还得用JS控制
  • 打赏
  • 举报
回复
会被遮挡.框架内的框架????
我不明白你指的意思,但现在不是遮挡的问题,而是iframe缩小了,而且是全部按比例缩小的


也就是我说的那意思

我只是看错了你的文件名!!

yuanw 2008-02-28
  • 打赏
  • 举报
回复
竟然自己不可以修改帖子?

上面的tmp.htm是打印稍微正常的方式,最不正常的是把style改为:

<style>
#divDetail {
border: solid 1px black;
width: 750px;
height: 520px;
position: absolute;
top: 55px;
left: 200px;
z-index: 20;
}
</style>


就是加上left的定位.
cnchart 2008-02-28
  • 打赏
  • 举报
回复
楼主你都知道设置table宽度为650时刚好一页纸的宽度。


当你的tmp1.htm在iframe时。你那页面tmp1.htm没有设置CSS:body{margin:0px}它会有个边距。

而你的iframe又有个border 1px,加上表格边框的宽度几个px,加起来都不止650px了,所以你在父页面打印时会有问题。
yuanw 2008-02-28
  • 打赏
  • 举报
回复
会被遮挡.框架内的框架????
我不明白你指的意思,但现在不是遮挡的问题,而是iframe缩小了,而且是全部按比例缩小的
myvicy 2008-02-28
  • 打赏
  • 举报
回复
<style>
#divDetail {
border: solid 1px black;
width: 750px;
height: 520px;
position: absolute;
top: 55px;
left: 200px;
z-index: 20;
}
</style>

当你在iframe内的时候,这个left200会向左移动,会被遮挡.框架内的框架.
加载更多回复(2)

61,115

社区成员

发帖
与我相关
我的任务
社区描述
层叠样式表(英文全称:Cascading Style Sheets)是一种用来表现HTML(标准通用标记语言的一个应用)或XML(标准通用标记语言的一个子集)等文件样式的计算机语言。
社区管理员
  • HTML(CSS)社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧