I created an iframe
in the custom HTML of 'blogspot'.
In the src
of the iframe
there is the link to 'Apps Script' (/.../exec).
In the .gs
of 'Apps Script', there is the doGet
below:
function doGet() {
const html = HtmlService.createHtmlOutputFromFile("blogspot");
return html.setXFrameOptionsMode(HtmlService.XFrameOptionsMode.ALLOWALL);
}
The blogspot
file is the HTML page of my blogger. I did this to avoid editing the HTML in blogger itself.
doGet
is working correctly.
However, when I tried to do a POST
using fetch
inside the 'blogspot' HTML (iframe content), then I got the error below:
userCodeAppPanel:1 Access to fetch at '/.../exec' from origin 'https://...-script.googleusercontent' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.
I looked for other CORS
resolutions here on the forum, but I didn't find what I'm looking for.
How can I solve the problem?
I created an iframe
in the custom HTML of 'blogspot'.
In the src
of the iframe
there is the link to 'Apps Script' (https://script.google/macros/s/.../exec).
In the .gs
of 'Apps Script', there is the doGet
below:
function doGet() {
const html = HtmlService.createHtmlOutputFromFile("blogspot");
return html.setXFrameOptionsMode(HtmlService.XFrameOptionsMode.ALLOWALL);
}
The blogspot
file is the HTML page of my blogger. I did this to avoid editing the HTML in blogger itself.
doGet
is working correctly.
However, when I tried to do a POST
using fetch
inside the 'blogspot' HTML (iframe content), then I got the error below:
userCodeAppPanel:1 Access to fetch at 'https://script.google/macros/s/.../exec' from origin 'https://...-script.googleusercontent' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.
I looked for other CORS
resolutions here on the forum, but I didn't find what I'm looking for.
How can I solve the problem?
- 1 Would you be able to provide your whole script, and also your expected output so that we can further help you. – Patsytalk Commented Mar 28 at 4:21
- Use simple requests. – TheMaster Commented Mar 28 at 5:22
1 Answer
Reset to default 1If you want to make a POST request to a Google Apps Script web application, it should include a doPost function
Example
function doPost(e){
console.log(JSON.stringify(e, null, " ");
return ContentService.createTextOutput('Hello world!')
}
Reference
- https://developers.google/apps-script/guides/web