如何将自定义 javascript 添加到谷歌网站?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10874147/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
how to add custom javascript to google sites?
提问by jeffery_the_wind
How do I get the ability to add/edit the JS on a google sites site? This way I want to use jQuery and jQuery UI to manipulate the look and feel of the site.
如何获得在 google 站点上添加/编辑 JS 的能力?通过这种方式,我想使用 jQuery 和 jQuery UI 来操纵站点的外观。
To be clear, I am not talking about all google sites, just the create-your-own system google has made, called "Google Sites" -> https://sites.google.com/.
需要明确的是,我不是在谈论所有谷歌网站,只是谷歌创建的自己创建的系统,称为“谷歌网站”-> https://sites.google.com/。
On the howto page, there is this: Unsupported features
在howto 页面上,有这个:不支持的功能
The HTML Box tool currently doesn't support the following features:
iframes JavaScript code can't create any script, image or link tags Document/window onload and onready functions. You can place any JavaScript at the end of code that needs to load after the document loads.
HTML Box 工具目前不支持以下功能:
iframes JavaScript 代码不能创建任何脚本、图像或链接标签 Document/window onload 和 onready 函数。您可以在需要在文档加载后加载的代码末尾放置任何 JavaScript。
Does that mean HTML tool cannot create tags? even though they are in the demo above?
这是否意味着 HTML 工具无法创建标签?即使它们在上面的演示中?
回答by duskwuff -inactive-
The Google Sites help explains how to add custom HTML/CSS/JS content:
Google 协作平台帮助解释了如何添加自定义 HTML/CSS/JS 内容:
- Go to the Google Sites page that you'd like to embed HTML in.
- Go to the Insert menu and select HTML Box.
- In the dialog that opens, add HTML, CSS and/or Javascript code.
- When you're done, click Save.
- To preview your embedded HTML, click Save on the Google Site page.
- 转到您要在其中嵌入 HTML 的 Google 协作平台页面。
- 转到插入菜单并选择 HTML 框。
- 在打开的对话框中,添加 HTML、CSS 和/或 Javascript 代码。
- 完成后,单击保存。
- 要预览嵌入的 HTML,请单击 Google 站点页面上的保存。
It goes on to note that "code from one HTML box can't interact with or refer to code outside of the HTML box, including other HTML boxes" -- presumably, each "HTML box" is a separately sandboxed iframe element. As such, your ability to use JS to "manipulate the look and feel of the site" will be pretty limited.
它继续指出“来自一个 HTML 框的代码不能与 HTML 框之外的代码交互或引用该 HTML 框之外的代码,包括其他 HTML 框”——据推测,每个“HTML 框”都是一个单独的沙盒 iframe 元素。因此,您使用 JS 来“操纵网站的外观和感觉”的能力将非常有限。
回答by Hugo O.
Another alternative is writing your own Gadget
另一种选择是编写自己的小工具
"Gadgets are small web applications that can be added to web pages. Gadgets are XML files that typically wrap HTML and JavaScript" as explained by a Google Sites Guru that goes by the name Mori. https://sites.google.com/site/mori79/html-gadgets
“小工具是可以添加到网页的小型 Web 应用程序。小工具是通常包装 HTML 和 JavaScript 的 XML 文件”,正如名为 Mori 的 Google Sites Guru 所解释的那样。 https://sites.google.com/site/mori79/html-gadgets
You can also find more information in Google Developers site: https://developers.google.com/google-apps/sites/gadgets/site_gadgets?hl=en
您还可以在 Google Developers 站点中找到更多信息:https: //developers.google.com/google-apps/sites/gadgets/site_gadgets?hl=en
Hope it helps.
希望能帮助到你。
回答by activars
Google Site has a good documentation, and you cannot use any JavaScript against their program policy.
Google 站点有一个很好的文档,您不能违反他们的计划政策使用任何 JavaScript 。
Please read the documentation, it lists details of the steps for inserting custom CSS, JavaScript and general HTML.
请阅读文档,它列出了插入自定义 CSS、JavaScript 和通用 HTML 的步骤的详细信息。