3

I am trying to create a Google Document that has complex questions we ask clients. I want to add a link at the end of each question that will launch a pop-up for additional information.

I currently have a .gs file that houses the script below:

function showDialog() {
  var html = HtmlService.createHtmlOutputFromFile('Help File.html')
      .setWidth(400)
      .setHeight(300);
  DocumentApp.getUi() // Or DocumentApp or FormApp.
      .showModalDialog(html, <b>Hello World!</b> );
  }

I also have a .html file with the following code:

< div>
Hello, world! 

< input type="button" value="Close" onclick="google.script.host.close()" />
< /div>}

Is there a way to embed this into a link on the Google Doc? Currently, I am able to click "Run" from the Google Apps Script to make the pop-up window work.

4
  • Couldn't you copy the URL of the running script window, and use that as a link in your Google Document? Apr 22, 2014 at 14:22
  • I'm not sure I understand. The URL of the script window shouldn't be accessible by anyone. The pop-up window doesn't have a URL. Can you please clarify? Apr 22, 2014 at 16:00
  • Ah, you're right. With .showModalDialog() there's no separate window with its own URL. See my answer below. Apr 23, 2014 at 8:09
  • I would go for the sidebar, see answer I gave on that: webapps.stackexchange.com/a/45980/29140 Apr 23, 2014 at 11:46

1 Answer 1

2

You could deploy your script as a web app, which implies implementing a doGet() method. In this method, you define your HTML content.

You can then access your script by the URL that is displayed in the Deploy as web app dialog. This URL could then be used in a link in your document.

However, the web app content is not displayed in a pop-up, so this might not solve your problem completely. You might want to create a sidebar. See the documentation for this.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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