Anand Deshmukh
Anand Deshmukh

Reputation: 1126

How to redirect to specific page from Google Script

I have implemented Google Script for sending an email to the specific user.

I reffered the code from here.

My problem statement is as follows :

Instead of sending the response to the user I want to navigate the user to specific website say https://stackoverflow.com what changes I need to do in my code.

Here is my code

var TO_ADDRESS = "[email protected]";

function doPost(e) {

    try {
        Logger.log(e);
        MailApp.sendEmail(TO_ADDRESS, "Contact Form Submitted", JSON
                .stringify(e.parameters));

        return HtmlService
                .createHtmlOutput("https://stackoverflow.com");

    } catch (error) {
        Logger.log(error);
        return ContentService.createTextOutput(JSON.stringify({
            "result" : "error",
            "error" : e
        })).setMimeType(ContentService.MimeType.JSON);
    }

}

What I tried to do is to navigate on https://stackoverflow.com but instead of navigation it's printing on browser as a response

Please let me know what changes I need to do in my code.

Upvotes: 0

Views: 130

Answers (1)

Chris
Chris

Reputation: 2107

There is no built in why of doing it yet as far as I know. This is the trick I've been using for a while:

function doGet(){
  return HtmlService.createHtmlOutput("<script>window.top.location.href = 'https://stackoverflow.com'</script>");
}

It does the trick.

Upvotes: 1

Related Questions