0

When I do:

var file = DriveApp.createFile(pdf);

and add a 'succes' screen:

var html = HtmlService.createHtmlOutputFromFile('page')
.setSandboxMode(HtmlService.SandboxMode.IFRAME)
.setWidth(300)
.setHeight(100);
DocumentApp.getUi() 
.showModalDialog(html, 'Done!');

How do I get button on this screen with a link to the made file? Can I use:

file.getUrl()

What code do I put on the html page?

<input type="button" value="OK" onclick="???" />

Any pointers are welcome.

  • Check this [SO question](http://stackoverflow.com/questions/6876819/how-do-you-add-ui-inside-cells-in-a-google-spreadsheet-using-app-script), it can help you to add a button in your script. – KENdi Jan 17 '17 at 14:44
  • Maybe my question was not that clear. What I need to know is how to 'store' the URL of the new created file in a button. The button is made with html and is shown with HtmlService. This is for Google Doc and not Spreadsheet. Anyone? – William de Smet Jan 17 '17 at 16:43

2 Answers2

0

I would try to use the getid()

and then try something like:

Var fileIds =[];

//  Logger.log("https://drive.google.com/uc?export=download&id=" + fileIds[i]);
OblongMedulla
  • 1,471
  • 9
  • 21
0

You will want to use .createTemplateFromFile(). This will allow you to pass info from your script to your modal dialog. In Code.gs it will look something like this:

var html = HtmlService.createTemplateFromFile("template");
//do not evaluate your html template, yet!

//get file url to pass to template
var fileUrl = file.getUrl();

//pass fileUrl to the html template as though it were a parameter of the
//html object
html.url = fileUrl;

//evaluate template and set features
var output = html.evaluate()
                 .setSandboxMode(HtmlService.SandboxMode.IFRAME)
                 .setWidth(300)
                 .setHeight(100);

DocumentApp.getUi().showModalDialog(output, 'Done!');

Now, in your html template file, use a printing scriptlet to retrieve the file's url for use in your custom button:

<a href="<?= url ?>" target="_blank"><button>Open file</button></a>

This should open your new file in a new window.

Silinus
  • 168
  • 4