2

Is is possible to embed a HTMLService app in an iframe?

Embedded Example: http://jsbin.com/axesex/1/edit

The app can be embedded within Google Site but not into any other standard web page. The console throw the error...

Refused to display 'https://script.google.com/a/macros/netpremacy.com/s/AKfycbxITmxBMsHIh_u82tbvfICzNesEUJh2MRe7izyDE9cgvaLPCZI/exec' in a frame because it set 'X-Frame-Options' to 'SAMEORIGIN'.

If you need any more information please let me know.

1

3 Answers 3

4

Updated 3/24/2017

Yes, but you need to set an extra flag on your output to allow it to be IFRAMEd:

// Serve HTML with no X-Frame-Options header (in Apps Script server-side code).
var output = HtmlService.createHtmlOutput('<b>Hello, world!</b>');
output.setXFrameOptionsMode(HtmlService.XFrameOptionsMode.ALLOWALL);
Sign up to request clarification or add additional context in comments.

5 Comments

Thanks Eric. Do you know why not? As an enterprise reseller this would be very useful to integrate HtmlService apps into existing in house enterprise web applications or intranet sites. Could you give me a bit of detail as to why this isn't available (yet)? This question originally came from me trying to embed a HtmlService app in a chrome Extension. I'd then force the chrome extension out to all users in a domain. The app would be used by end users during a pilot to capture informal feedback. Any ideas or workarounds?
I believe there are security concerns that prevent it at the moment.
OK. Thanks. I build a workaround to have a standard html form which sends a get request with the data in query strings. I works well from my Chrome extension.
I did this, however it still isn't working. Specifically I created a web-app displaying a table from a google sheet (as per bpwebs.com/pull-data-from-google-sheets-to-html-table), and am looking to embed that in a wordpress page.
0

It seems you can do that using setxframeoptionsmodemode:

//-- Serve HTML with no X-Frame-Options header (in Apps Script server side code).
var output = HtmlService.createHtmlOutput('<b>Hello, world!</b>');
output.setXFrameOptionsMode(HtmlService.XFrameOptionsMode.ALLOWALL);

Can read more about this in: https://developers.google.com/apps-script/reference/html/html-output#setxframeoptionsmodemode

Comments

-2

A possible equivalent might be to use JSONP. Basically modify the Google Apps script to output JSON (of a text/javascript mime-type) that is passed as a parameter to a function (which you'll create on the client side. The output of the apps script will look like:

client_side_handler(JSON HERE...);

And in your client page you'll have a script with something like:

function client_side_handler(json){
    //make all my wildest dreams come true here.
}

To call the apps script, you'll have another script tag that specifies the apps script as a src. Thankfully, script tags don't have the cross-site limitation that iframes do.

1 Comment

You can according to documentation

Your Answer

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.