继上次使用jcob解析word为html后,出现的页面大小没法设定的问题,最后是用iframe固定了页面的显示尺寸,同时考虑到安全问题,iframe的src值为动态页面加载的..
使用jquery:
$(document).ready(function(){
var url = "";
$.ajax({
type:"POST",
url:url,
success:function(data){
$('#urlIframe').attr("src",data);
}
});
})
开始以为这样就万事大吉了,但如果word中原本有的超链接解析过来后,链接都是在当前页面刷新的,而用了iframe去固定页面后,显示效果惨不忍睹..
后来就使用jquery去控制iframe下面包含的静态网页的链接..
var ifrmdom=$(window.frames["urlIframe"].document);
ifrmdom.find("a").attr("target","_blank");
测试过程中,老是不生效..原因是我把这段代码同时也放到了上面的加载中,那时候的src还是空值...
onload='Javascript:ReSizeiFrame(this)'中..成功..
<%@ page language="java" pageEncoding="GBK"%>
<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean"%>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html"%>
<%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic"%>
<%@ page import="com.pujin.common.WebConstants"%>
<%
String contextPath = WebConstants.GLOBAL_WEB_ROOT;
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<script type="text/javascript" src="<%=contextPath%>/resources/common/js/jquery/jquery-1.4.2.js"></script>
<script type="text/javascript">
$(document).ready(function(){
var url = "";
$.ajax({
type:"POST",
url:url,
success:function(data){
$('#urlIframe').attr("src",data);
}
});
})
function SetCwinHeight(obj)
{
var cwin=obj;
if (document.getElementById)
{
if (cwin && !window.opera)
{
if (cwin.contentDocument && cwin.contentDocument.body.offsetHeight)
cwin.height = cwin.contentDocument.body.offsetHeight;
else if(cwin.Document && cwin.Document.body.scrollHeight)
cwin.height = cwin.Document.body.scrollHeight;
}
}
}
var FFextraHeight = 0;
if(window.navigator.userAgent.indexOf("Firefox")>=1)
{
FFextraHeight = 16;
}
function ReSizeiFrame(iframe)
{
//放这里了..
var ifrmdom=$(window.frames["urlIframe"].document);
ifrmdom.find("a").attr("target","_blank");
if(iframe && !window.opera)
{
iframe.style.display = "block";
if(iframe.contentDocument && iframe.contentDocument.body.offsetHeight)
{
iframe.height = iframe.contentDocument.body.offsetHeight + FFextraHeight;
}
else if (iframe.Document && iframe.Document.body.scrollHeight)
{
iframe.height = iframe.Document.body.scrollHeight;
}
}
}
</script>
</head>
<body>
<iframe width="100%" height="80" onload='Javascript:ReSizeiFrame(this)' src="" frameborder="0" align="center"/>
<iframe id="urlIframe" width="595" height="10" onload='Javascript:ReSizeiFrame(this)' src="" frameborder="0" align="center"/>
</body>
</html>