如何使用 iframe 渲染仪表盘
正文来自原稿。把 ThingsBoard 仪表盘嵌到任意站点时,最简方式是公开链接 + iframe。
1、页面代码
html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>仪表盘</title>
<style>
html, body {
margin: 0;
padding: 0;
height: 100%;
overflow: hidden;
}
iframe {
width: 100%;
height: 100%;
border: none;
}
</style>
</head>
<body>
<iframe src="http://YOUR_TB_HOST:8080/dashboard/DASHBOARD_ID?publicId=PUBLIC_ID">
</iframe>
</body>
</html>将 YOUR_TB_HOST、DASHBOARD_ID、PUBLIC_ID 换成实际公开仪表盘地址后,用浏览器直接打开该 HTML 即可。
2、注意
- 仪表盘需开启 公开访问,URL 带正确
publicId。 - 跨域、HTTPS 混用、X-Frame-Options 若被网关限制,需在反向代理放行嵌入。
- 内网 IP 仅示例;生产用域名与 HTTPS。
3、小结
全屏 iframe + 公开仪表盘链接,即可快速做门户嵌入;若要去掉 Powered by,见 去掉 Powered by。
