1 year ago

#365940

test-img

devoloper

how to redirect to another page using google web script?

I made successful code to redirect to another page using web script just in case I add query string manually. like this [main url]?Page=Partial

the doGet code

  function doGet(e) {
    var template;
    var pageName = e.parameter.page === undefined ? "Index" : e.parameter.page;  
    if (pageName === "Index") {
      template = HtmlService.createTemplateFromFile(pageName);
    }else{
      var url = ScriptApp.getService().getUrl();
      var getPageUrl = url + "?page=" + pageName;
      template = HtmlService.createTemplateFromFile(pageName);
      template.url = getPageUrl;
    }

    return template.evaluate();
  }

but when I try to href using anchor element It never work

  function href(pageName){
      var url = ScriptApp.getService().getUrl();
      var fullPageUrl = url + "?page=" + pageName;
      return fullPageUrl;
  }

then I use this in Index.html like this

 <a href="<?= href('Partial') ?>"></a>

notes:
if I do inspect for the page and click the href link it works well, but clicking directedly never work and come back with a page with error Forbidden Error 403

clicking href link content, when inspect page, or changing url manually only the successful ways to redirect to another page. and it never works by clicking directly on the href element and it comes back instead with error Forbidden Error 403

javascript

google-apps-script

web-applications

http-status-code-403

0 Answers

Your Answer

Accepted video resources