Technologies:
Tolerim
19 hours ago
How can I permit embedding a Google script on certain domains?
In this Google script app, the provided code returns an HTML template for 'form.html'. To enable embedding of the script on all domains, the 'setXFrameOptionsMode' is set to 'ALLOWALL'. If you want to restrict embedding to specified domains only, you can modify the code by setting 'setXFrameOptionsMode' to 'ALLOW-FROM [website URL]', where [website URL] is the domain name you want to allow. For example, if you want to allow embedding only on 'example.com', the code would look like this:
Hope this helps! Let me know if you have any other questions.
function doGet() {
return HtmlService.createTemplateFromFile('form.html')
.evaluate()
.setXFrameOptionsMode('ALLOW-FROM https://example.com/');
}
Answers(1)
Tolerim
19 hours ago
Verified Answer
To allow embedding the code only by specified domains, you can modify the code above by setting the XFrameOptionsMode to ALLOW-FROM and specifying the domains you want to allow.
Here's an example:
function doGet() {
return HtmlService.createTemplateFromFile('form.html')
.evaluate()
.setXFrameOptionsMode(HtmlService.XFrameOptionsMode.ALLOWFROM)
.setXFrameOptionsUrl('https://www.example.com');
}
In this example, we have set the XFrameOptionsMode to ALLOWFROM and specified the domain as https://www.example.com. This will allow embedding of the script on https://www.example.com only. You can add multiple domains using a comma-separated list.