爲了幫助打印,我動態生成了一個iFrame,然後用一些內容填充它。這適用於PC和Mac上的IE6,IE8,Chrome和Firefox。問題出於某種原因,它在IE7上無法正常工作。IE7將不會在動態生成的iFrame中顯示圖像
在IE7中,圖片不顯示;相反,他們表現爲破碎的圖像。查看時結果相同。這很奇怪,因爲就像我說的,它在IE6和IE8中工作正常。
任何想法?我已經發布了一個簡單化的副本here
這裏的源代碼(如示例所示):
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-type" content="text/html;charset=UTF-8" />
<title>iframe print test</title>
<script type="text/javascript" src="jquery-1.4.2.min.js"></script>
<script type="text/javascript">
function printIFrameFunc(id)
{
var iframe = document.frames ? document.frames[id] : document.getElementById(id);
var ifWin = iframe.contentWindow || iframe;
iframe.focus();
ifWin.print();
return false;
}
function printfra() {
$("iframe#printIFrame").remove();
// Create an iframe which will be populated with the data to be printed...
$('body').append('<iframe id="printIFrame"></iframe>');
// !!! This next line commented so the iframe will be visible on the screen
//$("iframe#printIFrame").attr('style','position:absolute;left:-500px;top:-500px;');
// Don't do anything on the iframe until it's ready to go
if ($.browser.webkit)
$("iframe#printIFrame").ready(iframeloadedprint);
else
$("iframe#printIFrame").load(iframeloadedprint);
function iframeloadedprint() {
var printBody = $("iframe#printIFrame").contents().find('body');
printBody.html($("#mainContainer").html());
printIFrameFunc('printIFrame');
}
return false;
}
</script>
</head>
<body>
<div id="mainContainer">
<img src="dash.png" alt="test image" />
<a href="#" onclick="printfra();">Click here to print</a>
</div>
</body>
任何幫助或建議,將不勝感激!