隐藏 google 可视化 api 的 javascript 内容
我正在使用 google 可视化 api javascript 来显示我网站上的一些图像。因此,当我使用 javascript 时,如果用户单击“查看源代码”,则会泄露 javascript 源代码中的所有信息,这是我不希望发生的情况。
所以我尝试将 javascript 保存到iechart.js 文件中并像这样调用它
和然后在同一页面上像这样调用div中图表的ID。但该图表未显示在网页上。
这是index.php的代码
我确信我的代码对于显示的图表是正确的,因为当我放置代码而不是 piechart.js 时,我可以看到图表并沿着通过代码,值也会被显示。请在这里帮助我。我应该如何以及在哪里调用 div?
piechart.js 代码(如果有人能够正确对齐此 javascript 代码,我将不胜感激。) <脚本类型=“text/javascript”>
`
google.load('visualization', '1', {packages: ['corechart']}); <script type="text/javascript">
function drawVisualization() {
// Create and populate the data table.
var data = new google.visualization.DataTable();
data.addColumn('string', 'Browser');
data.addColumn('number', 'Visits');
data.addRows(5);
data.setValue(0, 0, 'Internet Explorer (50.8%)');
data.setValue(0, 1, 50.81);
data.setValue(1, 0, 'Firefox (25.3%)');
data.setValue(1, 1, 25.30);
data.setValue(2, 0, 'Safari (16.09%)');
data.setValue(2, 1, 16.09);
data.setValue(3, 0, 'Chrome (7.53%)');
data.setValue(3, 1, 7.53);
data.setValue(4, 0, 'Opera (0.25%)');
data.setValue(4, 1, 0.25);
// Create and draw the visualization.
new google.visualization.PieChart(document.getElementById('piechart')).
draw(data, {title:"Visits by Browser",width:420, height:300, backgroundColor:'cccccc'});
}
google.setOnLoadCallback(drawVisualization);
</script> `
I am using google visualization api javascript for some images on my website. So when i am using the javascript and if the user clicks on view source, it is revealing all the information in the javascript source code which i do not want it to happen.
So i have tried to save the javascript into piechart.js file and call it like this
<script type="text/javascript" src="piechart.js"></script>
and then call the ID of the chart in the div like this on the same page. But the chart is not being displayed on the webpage.
Here is the code of index.php
<script type="text/javascript" src="piechart.js">
<div id="piechart"></div>
I am sure my code is correct for the chart to display because when i place the code instead of the piechart.js i can see the chart and along with code, the values are also being shown. Please help me here. How and where should i call the div?
piechart.js code (would appreciate if someone could align this javascript code correctly.)<script type="text/javascript">
`
google.load('visualization', '1', {packages: ['corechart']});
<script type="text/javascript">
function drawVisualization() {
// Create and populate the data table.
var data = new google.visualization.DataTable();
data.addColumn('string', 'Browser');
data.addColumn('number', 'Visits');
data.addRows(5);
data.setValue(0, 0, 'Internet Explorer (50.8%)');
data.setValue(0, 1, 50.81);
data.setValue(1, 0, 'Firefox (25.3%)');
data.setValue(1, 1, 25.30);
data.setValue(2, 0, 'Safari (16.09%)');
data.setValue(2, 1, 16.09);
data.setValue(3, 0, 'Chrome (7.53%)');
data.setValue(3, 1, 7.53);
data.setValue(4, 0, 'Opera (0.25%)');
data.setValue(4, 1, 0.25);
// Create and draw the visualization.
new google.visualization.PieChart(document.getElementById('piechart')).
draw(data, {title:"Visits by Browser",width:420, height:300, backgroundColor:'cccccc'});
}
google.setOnLoadCallback(drawVisualization);
</script> `
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不需要仅仅为了隐藏你的源代码而这样做;这是不可能的,因为即使您将 javascript 代码放在其他文件中,源代码仍然可用/可见。
您可能想要混淆您的代码,请查看:
或者您可能想要具有适当许可的版权您的代码。
No need to do that just to hide your source code; and that is not possible because the source code will still be available/visible even if you put your javascript code in some other file.
You may want to obfuscate your code, have a look at:
Or you may want to copyright your code with appropriate license.