【发布时间】:2021-05-24 20:00:02
【问题描述】:
这个 html 根据点击的按钮显示 3 个 pdf 在 Firefox 和 Chrome 中有效。第一次单击第二个或第三个按钮后,它不会在 Edge 中显示 pdf。但是当第二次单击按钮时,它会显示 pdf。 什么会导致这个?如果它是 Edge 中的错误,是否有解决方法?
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
body {
display: flex;
flex-direction: column;
align-items: center;
overflow: hidden;
}
.row-container {
flex: 1 1 100vh;
display: flex;
flex-direction: column;
overflow: hidden;
width: 100%;
background-color: red;
}
.first-row {
background-color: beige;
}
.second-row {
flex: 1 1 auto;
flex-direction: column;
display: flex;
border: 3px solid lightblue;
min-height: 0;
overflow: hidden;
}
.frame {
flex: 1 1 auto;
border: 0;
}
.active {
display: block;
}
.hidden {
display: none;
}
.selected {
color: white;
background-color: blue;
}
.not-selected {
color: black;
background-color: lightblue;
}
</style>
</head>
<body>
<div class="row-container">
<div class="first-row">
<p>just some text here</p>
<nav>
<div id="nav-tab">
<button id="but1" class="button selected">Dummy</button>
<button id="but2" class="button not-selected">Lorem</button>
<button id="but3" class="button not-selected">Resume</button>
</div>
</nav>
</div>
<div class="second-row" id="nav-tabContent">
<iframe class="frame active" id="pdf-but1"
src="https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf">
</iframe>
<iframe class="frame hidden" id="pdf-but2"
src="https://file-examples-com.github.io/uploads/2017/10/file-sample_150kB.pdf">
</iframe>
<iframe class="frame hidden" id="pdf-but3"
src="https://upload.wikimedia.org/wikipedia/commons/c/cc/Resume.pdf">
</iframe>
</div>
</div>
<script>
var buttons = document.getElementsByClassName("button");
var frames = document.getElementsByClassName("frame");
var i
function click() {
for (i = 0; i < buttons.length; i++) {
if (buttons[i].id != this.id) {
buttons[i].setAttribute("class", "button not-selected");
frames[i].setAttribute("class", "frame hidden");
}
}
this.setAttribute("class", "button selected");
document.getElementById("pdf-" + this.id).setAttribute("class", "frame active");
}
for (i = 0; i < buttons.length; i++) {
buttons[i].addEventListener("click", click)
}
</script>
</body>
</html>
【问题讨论】:
标签: javascript html pdf iframe microsoft-edge