Skip to content

Instantly share code, notes, and snippets.

@annafergusson annafergusson/Code.gs Secret
Last active Oct 17, 2018

Embed
What would you like to do?
Random redirect using Google Apps Script
function doGet() {
var webpages = [];
//---------------just change the webpage URLs
//the webpages need to hosted on https sites - if you want more than two just create a new line using the same code as below
//just change the link to the google form
webpages.push("https://docs.google.com/forms/d/e/1FAIpQLSfLfuayN7YVhFRzAWG87ArEeML6ltEUgDOB5rA9F0KIH2u_5w/viewform?usp=sf_link");
webpages.push("https://docs.google.com/forms/d/e/1FAIpQLSdjjtjCVrovMpGDH-9JlBwmXI5kNgK_EmJM1sfBRFDw3C4wWg/viewform?usp=sf_link");
//------------------------------------------
var random_page = Math.floor(Math.random()*webpages.length);
var redirect = webpages[random_page];
return HtmlService.createHtmlOutput("<script>location.href = '" + redirect + "';</script>");
//line below requires authorisation but also works - thanks Nikolai Cook
//return HtmlService.createHtmlOutput(UrlFetchApp.fetch(redirect));
}
@annafergusson

This comment has been minimized.

Copy link
Owner Author

commented Nov 9, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.