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);
5
  • 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? May 30, 2013 at 20:38
  • 1
    I believe there are security concerns that prevent it at the moment. Jun 4, 2013 at 19:01
  • 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. Jun 11, 2013 at 11:57
  • Wrong, according to: developers.google.com/apps-script/reference/html/… Feb 28, 2017 at 4:21
  • 1
    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.
    – Green05
    Jul 11, 2021 at 18:21
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

-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
  • You can according to documentation Feb 28, 2017 at 4:27

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.