Can you assign scripts to page elements (shapes etc.)?

后端 未结 2 1844
不思量自难忘°
不思量自难忘° 2021-01-24 03:52

I want to make an interactive slideshow for students.

I want to add shapes, so when you click on the shape it will run an Apps Script script. This is possible in Google S

2条回答
  •  囚心锁ツ
    2021-01-24 04:14

    There is no way to run a container-bound script by clicking a shape in Google Slides like you can in Google Sheets. But, you can accomplish a similar effect by adding a shape with a link to a web app that runs your script when opened. For Example, here is a script for a web app that changes the text on the first shape of the first slide whenever someone visits it.

    function doGet() {
       const presentation = SlidesApp.openById(id); // presentation id
       const slide = presentation.getSlideById(id); // slide id
       const textBox = slide.getShapes().filter(_s => _s.getObjectId() === objectId)[0].getText(); // id of your text box object
       const clicks = Number(textBox.asString());
       textBox.setText(clicks + 1);
       return ContentService.createTextOutput("Thanks for clicking!"); //message to display when user visits your webapp
    }
    
    

    Here is a working example: Google Slide Presentation with Clickable Button

提交回复
热议问题