<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>pdfEmbed使用</title>
</head>
<body>
<div id="test">
<embed width="600" height="880" type="application/pdf" src="ECMAScript 6入门.pdf"></embed>
</div>
<script>
function pdfEmbed(){
var pdfEmbed = document.createElement('EMBED'); //创建embed对象
pdfEmbed.setAttribute('src','ECMAScript 6入门.pdf'); //设置src属性
pdfEmbed.setAttribute('type','application/pdf'); //设置type属性
pdfEmbed.setAttribute('width','600'); //设置width属性
pdfEmbed.setAttribute('height','880'); //设置height属性
document.getElementById('test').appendChild(pdfEmbed); //添加节点
}
//函数调用
(function(){
pdfEmbed();
})();
</script>
</body>
</html>

左边的PDF是H5embed标签的使用方法,右边是embed对象的使用方法。
网友评论