【发布时间】:2012-06-03 16:23:39
【问题描述】:
<!--
You are free to copy and use this sample in accordance with the terms of the
Apache license (http://www.apache.org/licenses/LICENSE-2.0.html)
-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<title>
Google Visualization API Sample
</title>
<script type="text/javascript" src="http://www.google.com/jsapi"></script>
<script type="text/javascript">
google.load('visualization', '1', {packages: ['corechart']});
</script>
<script type="text/javascript">
function drawVisualization() {
// Create and populate the data table.
var data = google.visualization.arrayToDataTable([
['Task', 'Hours per Day'],
['Work', 11],
['Eat', 2],
['Commute', 2],
['Watch TV', 2],
['Sleep', 7]
]);
// Create and draw the visualization.
new google.visualization.PieChart(document.getElementById('visualization')).
draw(data, {title:"So, how was your day?"});
}
google.setOnLoadCallback(drawVisualization);
</script>
</head>
<body style="font-family: Arial;border: 0 none;">
<div id="visualization" style="width: 600px; height: 400px;"></div>
</body>
</html>
上面的代码在一个html文件中为我们生成了一个饼图。当我在浏览器中打开它时它可以工作。我们将文件命名为 popup.html。
然后我想用以下清单文件使它成为一个 Chrome 扩展:
{
"name": "History Visualizer",
"version": "1.0",
"manifest_version": 2,
"description": "Helps us analyze history stats in a visual way",
"browser_action": {
"default_icon": "icon.png",
"default_popup": "popup.html"
}
}
但是当我点击图标按钮时,饼图将无法加载。有人帮帮我吗?
EDIT:检查弹窗后的错误信息如下。
拒绝从“http://www.google.com/jsapi”加载脚本,因为 内容安全策略。拒绝执行内联脚本,因为 内容安全策略。
【问题讨论】:
-
右键单击扩展程序的工具栏图标,从上下文菜单中选择 Inspect Popup,从控制台面板复制错误消息并将其粘贴到此处。如果没有错误消息,请尝试通过在控制台中执行重新加载弹出窗口:
window.location.reload();。 -
@kdzwinel 谢谢。添加了错误消息。