【发布时间】:2020-01-24 19:35:57
【问题描述】:
我正在尝试使用 Tableau Online 中托管的仪表板重新创建 the example provided by Tableau here。 Tableau talks about modifying the URL of the JS API based on where the dashboard is hosted 的另一篇文章,我已尝试关注。
即使生成的嵌入需要显示登录信息,我希望该登录信息会显示在我网页上的嵌入输出/iframe 中。请参阅包含的代码。相反,我收到了 CORS 错误:
拒绝在框架中显示“https://10ay.online.tableau.com/site/jpl/views/JPLDashboard_V05_JUE/Awareness?:iid=2&:size=800,700&:embed=y&:showVizHome=n&:bootstrapWhenNotified=y&:tabs=n&:apiID=host0#navType=1&navSrc=Parse”,因为它将“X-Frame-Options”设置为“sameorigin”。
我采用的方法是否正确?如果可以使用 JS API 嵌入 Tableau Online 仪表板,我该如何避免 CORS 错误?
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>JPL Dashboard</title>
<script type="text/javascript" src="https://online.tableau.com/javascripts/api/tableau-2.min.js"></script>
<script type="text/javascript">
function initViz() {
var containerDiv = document.getElementById("vizContainer"),
//url = "http://public.tableau.com/views/RegionalSampleWorkbook/Storms",
url = "https://10ay.online.tableau.com/site/jpl/views/JPLDashboard_V05_JUE/Awareness?:iid=2",
options = {
hideTabs: true,
onFirstInteractive: function() {
console.log("Run this code when the viz has finished loading.");
}
};
var viz = new tableau.Viz(containerDiv, url, options);
}
</script>
</head>
<body>
<div id="vizContainer" style="width:800px; height:700px;"></div>
<script type="text/javascript">
(function () {
window.onload = function () {
initViz();
};
})();
</script>
</body>
</html>
【问题讨论】:
标签: javascript api cross-domain embed tableau-api