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

前端 未结 5 1373
栀梦
栀梦 2021-02-08 04:26

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

5条回答
  •  难免孤独
    2021-02-08 05:06

    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.

提交回复
热议问题