如何解决使用对象标记
|将HTML文件嵌入html。 我将pdf文档嵌入到html代码中。为此,我编写了这段代码。<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org
/TR/html4/loose.dtd\">
<html lang=\"en\">
<head>
<meta http-equiv=\"Content-Type\" content=\"text/html;charset=UTF-8\">
<title></title>
</head>
<body>
<object height=\"100%\" width=\"100%\" type=\"application/pdf\" data=\"yii.pdf#toolbar=1&navpanes=0&scrollbar=1&page=1&view=FitH\">
<p>It appears you don\'t have a PDF plugin for this browser. No biggie... you can <a href=\"/pdf/sample.pdf\">click here to download the PDF file.</a></p>
</object>
</body>
</html>
但是结果是FF4和IE9上的空白页嵌入了pdf文件,但其容器很小,几乎占页面的30%。如果我删除第一行,即DOCTYPE,则两个浏览器都会按原样呈现pdf文件。
以下代码可以正常工作。
<html lang=\"en\">
<head>
<meta http-equiv=\"Content-Type\" content=\"text/html;charset=UTF-8\">
<title></title>
</head>
<body>
<object height=\"100%\" width=\"100%\" type=\"application/pdf\" data=\"yii.pdf#toolbar=1&navpanes=0&scrollbar=1&page=1&view=FitH\">
<p>It appears you don\'t have a PDF plugin for this browser. No biggie... you can <a href=\"/pdf/sample.pdf\">click here to download the PDF file.</a></p>
</object>
</body>
</html>
我想在页面中使用doctype,以便其他页面正常工作。有没有办法解决包含doctype的第一个代码?
解决方法
我会尝试使用
<iframe>
元素。
如果不是,则可以将其转换为Flash,然后嵌入Flash。
另外,尝试<!doctype html>
看看它能做什么,这是HTML5的标准文档类型
, 这基本上是@tXK的答案(+1),但是具有有效的(经过战斗力测试)的代码:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
<title>Preview</title>
<style type=\"text/css\">
html,body {
margin: 0;
padding: 0;
border: 0;
height: 100%;
overflow: hidden;
}
iframe {
width: 100%;
height: 100%;
border: 0
}
</style>
</head>
<body>
<iframe src=\"\"></iframe>
</body>
</html>
, 有三种显示HTML格式的PDF的方法:使用嵌入,对象或iframe。不幸的是,由于hostContainer是未定义的,因此使用iframe不允许PDF内的Adobe Javascript将消息发布到HTML中的JS。因此,我被迫使用嵌入或对象。幸运的是,三十点的样式代码也非常适合对象。这是我的工作代码...
<!DOCTYPE html>
<html>
<head>
<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
<title>Preview</title>
<style type=\"text/css\">
html,body {
margin: 0;
padding: 0;
border: 0;
height: 100%;
overflow: hidden;
}
object {
width: 100%;
height: 100%;
border: 0
}
</style>
<script language=\"javascript\">
function handleMessage(msg) {
alert(\'got message \'+msg);
}
function setupHandler() {
document.getElementById(\"myPdf\").messageHandler = { onMessage: handleMessage };
}
</script>
</head>
<body onLoad=\"setupHandler();\">
<object id=\"myPdf\" type=\"application/pdf\" data=\"file_with_actions.pdf\">
Unable to open the PDF file.
</object>
</body>
</html>
您可以在此处阅读有关Javascript内容的更多信息。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。