首页 > 解决方案 > 嵌入文档时不需要的页面边框

问题描述

我可以在 Chrome 的新标签中显示 pdf。但我在页面周围看到一个不需要的框架。

我使用对象标签嵌入文档,但我也使用 iframe 始终显示边框(将 frameborder 设置为 0),也使用样式我没有更好的结果。我认为问题在于当我创建一个新文档时,这会为我创建一个 html 过度结构,而我不需要它。

这是我的 JavaScript 代码:

var windowTab= window.open();
var blob = new window.Blob([response], { type: 'application/pdf' });
var file = URL.createObjectURL(blob);
windowTab.document.write('<object data="' + file + '" style="border:0px; margin:0px; padding:0px; 
width:100%; height:100%;" allowfullscreen></object>')

这是生成的html:

<html>
<head>
</head>
<body>
 <!-- This is my document !-->
 <object data="blob:http://localhost:8080/f3a8347d-1052-4460-acc8-ecb8d6be0861" allowfullscreen="">
   <!-- this html is unnecessary --> 
   <html>
   <head></head>
   <body>
   <embed width="100%" height="100%" src="about:blank" type="application/pdf" 
   internalid="CAE747DCA94CCEFA3C50345F9D12986A">```</body>
</html>
</object>
</body>
</html>

标签: javascripthtmlcss

解决方案


Try setting all border to 0px or none

body,
html,
object,
embed{
    border: 0px !important;
}

Reference Link


推荐阅读