标题有时候需要展示pdf的嵌套页面
- 需要添加参数name,例如vscode下的访问地址,http://127.0.0.1:5500/pdf.html?name=阿里巴巴java开发规范
<!DOCTYPE html>
<html lang="cn">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>PDF</title>
</head>
<body style="height:100vh;padding: 0;margin: 0;">
<embed id="pdf" src="./pdf/阿里巴巴java开发规范.pdf" height="100%" style="width:100%;" type="application/pdf">
<script>
function getUrlParameter(parameterName,url){
url=url || window.location.href;
return (new URL(window.location.href)).searchParams.get(parameterName);
}
var name=getUrlParameter("name");
document.getElementById("pdf").setAttribute("src", "./pdf/" + name + ".pdf")
document.getElementsByTagName("title")[0].innerText=name;
</script>
</body>
</html>
- 展示效果
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/ceaaa39723dde55510f22f0c2b78024f.png#pic_center)