Set custom cookies using Google Apps Script

2019-08-31 04:55发布

问题:

is it possible to set a custom cookie through a Google Apps script gadget embedded in a Google site. I've been trying using the HtmlService class (through document.coookie in a script from the html file) but it doesn't seem to generate the cookie. I'm assuming this must be by design (i.e. Caja sanitisation). Is there another way?

Thanks

回答1:

It is not possible, by design, but you shouldn't need to; you can store information about the current user in UserProperties.



回答2:

It's acctually possible if you use the iframe option just like this:

function doGet(e) {
    return HtmlService.createHtmlOutputFromFile("index.html")
                .setSandboxMode(HtmlService.SandboxMode.IFRAME);
}
// after that you may use (On "index.html"):
// document.cookie = "cookieName=1234";

best regards.