在网页中,我想使用JavaScript
我尝试过
(display = "none"/"block")
显示或隐藏多个PDF文件。这项功能一直都有效,但在基于Chrome的浏览器中已经不起作用几个星期了(Firefox仍然正常工作)。我尝试过
\<iframe>
、\<object>
和\<embed>
,但都没有成功。Chrome(92.0.4515.159)只在第一次显示每个PDF。第二次,视图区域只会呈现灰色,在浏览器调试器中也没有显示问题。只要我调整浏览器窗口大小,PDF文件就能正确地显示出来。<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body style="height: 100vh;">
<embed id = "a" src="A.pdf" type="application/pdf" style="width: 100%;height: 100%;">
<embed id = "b" src="B.pdf" type="application/pdf" style="width: 100%;height: 100%;">
<script>
setInterval(toggleFunction, 1000);
let toggle = false;
function toggleFunction()
{
if (toggle) {
document.getElementById("a").style.display = "none";
document.getElementById("b").style.display = "block";
}
else {
document.getElementById("b").style.display = "none";
document.getElementById("a").style.display = "block";
}
toggle = !toggle;
}
</script>
</body>
</html>