Javascript 嵌入文档时不需要的页面边框
我可以在Chrome的新选项卡中显示pdf。 但是我在页面周围看到了一个不需要的框架 我使用object标记嵌入文档,但我也使用iframe始终显示边框(frameborder设置为0),也使用样式,我没有更好的结果。 我认为问题在于,当我创建一个新文档时,这会创建一个html超结构,我不需要它 这是我的javascript代码:Javascript 嵌入文档时不需要的页面边框,javascript,html,css,Javascript,Html,Css,我可以在Chrome的新选项卡中显示pdf。 但是我在页面周围看到了一个不需要的框架 我使用object标记嵌入文档,但我也使用iframe始终显示边框(frameborder设置为0),也使用样式,我没有更好的结果。 我认为问题在于,当我创建一个新文档时,这会创建一个html超结构,我不需要它 这是我的javascript代码: var windowTab= window.open(); var blob = new window.Blob([response], { type: 'appli
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>')
var windowTab=window.open();
var blob=new window.blob([response],{type:'application/pdf'});
var file=URL.createObjectURL(blob);
windowTab.document.write(“”)
这是生成的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>
```
尝试将所有边框设置为0px
或none
body,
html,
object,
embed{
border: 0px !important;
}
解决了在我的javascript中添加此行的问题:
newTab.document.write('<html><head><title>Document</title><style> body {margin:0px;} </style></head><body>');
newTab.document.write('documentbody{margin:0px;}');
在这里,我将显式边距设置为0,现在它可以正常工作了