網頁轉向

一、按下按鈕轉向

首頁:index.html

<!DOCTYPE html>

<html>

  <head>

    <base target="_top">

    <script>

      function redirectToPage1() {

        google.script.run.withSuccessHandler(updatePageContent).includePage1();

      }

     

      function updatePageContent(content) {

        document.open();

        document.write(content);

        document.close();

      }

    </script>

  </head>

  <body>

    <h1>Home - index.html</h1>

    <button onclick="redirectToPage1()">Redirect to Page 1</button>

  </body>

</html>

轉向:page1.html

<!DOCTYPE html>

<html>

  <head>

    <base target="_top">

  </head>

  <body>

    <h1>Page 1</h1>

    <p>這是Page 1的內容。</p>

  </body>

</html>

Code.gs

function doGet() {

  return HtmlService.createTemplateFromFile('index').evaluate();

}


function includePage1() {

  var page1Content = HtmlService.createTemplateFromFile('page1').getRawContent();

  return page1Content;

}

說明