How do I embed JavaScript code into a Google Sites page?

Aparna Khombhadia picture Aparna Khombhadia · Apr 27, 2012 · Viewed 22k times · Source

I have a Google Sites page. How can I embed JavaScript code in it, without implementing a gadget and adding JavaScript code in that?

Answer

Serge Populov picture Serge Populov · Sep 10, 2013

You can run some JavaScript code, but during page editing it will be automatically wrapped into a trivial gadget, and when rendering page it will be executed inside of iframe, and won't be able to interact with DOM of main page - this is prevented by security mechanisms of browser and Google Sites.

So, anything your script do, it will do in a sandbox of it's iframe, who's outer size is defined at page design time, if you don't want to implement a gadget.

And even if you implement a gadget with your script inside, it will also run in the same iframe sandbox. But gadget has some advantages, for example access to API, that allows to change size of iframe dynamically, and some others.