H5的embed标签和对象的使用

2018-11-28  本文已影响10人  最帅的坏兔子
<!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>
浏览器效果pdfEmbed.png

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

上一篇 下一篇

猜你喜欢

热点阅读