-1

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.com/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.com/macros/s/.../exec' from origin 'https://...-script.googleusercontent.com' 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?

Wicket
39.6k9 gold badges81 silver badges201 bronze badges
asked Mar 28, 2025 at 2:22
2
  • 1
    Would you be able to provide your whole script, and also your expected output so that we can further help you. Commented Mar 28, 2025 at 4:21
  • Use simple requests. Commented Mar 28, 2025 at 5:22

1 Answer 1

1

If 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

answered Mar 28, 2025 at 13:41
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.