2

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.

| improve this question | | | | |
  • Couldn't you copy the URL of the running script window, and use that as a link in your Google Document? – Vidar S. Ramdal Apr 22 '14 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? – user1880291 Apr 22 '14 at 16:00
  • Ah, you're right. With .showModalDialog() there's no separate window with its own URL. See my answer below. – Vidar S. Ramdal Apr 23 '14 at 8:09
  • I would go for the sidebar, see answer I gave on that: webapps.stackexchange.com/a/45980/29140 – Jacob Jan Tuinstra Apr 23 '14 at 11:46
1

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.

| improve this answer | | | | |

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.