[英]How do I use the Tableau Javascript API to embed dashboards in a webpage for dashboards hosted in Tableau Online?
我正在嘗試使用 Tableau Online 中托管的儀表板重新創建Tableau 在此處提供的示例。 Tableau 的另一篇文章討論了根據儀表板的托管位置修改 JS API 的 URL ,我試圖遵循。
盡管生成的嵌入應該需要顯示登錄名,但我希望登錄名顯示在我網頁上的嵌入輸出/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>
確保用於嵌入視圖的 URL 來自 Tableau Online 中的“共享”選項:
如果正確,嘗試在HTML header中添加: <meta http-equiv="X-Frame-Options" content="allow">
我希望它是有幫助的,吉吉
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.