0

My WebApp URL is this:

https://script.google.com/macros/s/[Deployment ID]/exec

It shows the form correctly. I have a button on top of this form to come back to home page. It only has to add ?page=home to the above url. But when I click that button URL is shown as following:

https://n-f22j6yycycwkqttwlgfk5eezyixnbwfyfih4bba-0lu-script.googleusercontent.com/userCodeAppPanel?page=home

So last parameter part is what I have expected with my webapp url, not with this:

...script.googleusercontent.com/userCodeAppPanel

which I do not understand so far.

What is userCodeAppPanel?

How to solve this problem?

I tried to create sample project for similar webapp with only three pages. But when I deployed I get other problem - not the above one. So I guess the question also should be changed now.I did change the question. New question is : Google WebApp URL if changed manually is working but via button href not working. Why?

GS doGet function: Within doGet i have following -

var html = doGetPageOrIndex(e);
return html;



function doGetPageOrIndex(e){
  var page = e.parameter.page
  return HtmlService.createHtmlOutputFromFile(page || 'index2')
    .addMetaTag('viewport', 'width=device-width, initial-scale=1')
    .setTitle('App Demo')
}

HTML page1

<!DOCTYPE html>
<html>
  <head>
    <base target="_top">
  </head>
  <body>
    <h3>Heading Page 1</h3>
    <p>Thanks Man</p>
  </body>
</html>

HTML page2

<!DOCTYPE html>
<html>
  <head>
    <base target="_top">
  </head>
  <body>
    <h4>Your Page2</h4>
    <p>You are welcome!</p>
  </body>
</html>

This demo is being copied from another user of stackoverflow.

here is Index2 HTML page code:

<!DOCTYPE html>
<html>
  <head>
    <base target="_top" />
    <title>Single Page App</title>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
    <style>
      h1 {
        text-align: center;
        margin: 2px;
        text-transform: uppercase;
        background-color: blue;
      }
      span:hover,
      a:hover {
        background-color: yellowgreen;
      }
      body {
        background-color: brown;
        color: white;
        font-size: 2em;
      }
      a:visited {
        color: white;
      }
    </style>
  </head>
  <body>
    <h1><span id="type">Multi</span> Page App </h1>
    <div id="main">Loading...</div>
    <script>
      //Change base url
      google.script.run
        .withSuccessHandler(url => {
          $('base').attr('href', url)
        })
        .getUrl()

      //Function to handle hash change
      function change(e) {
        let hash = e.location.hash
        if (!hash) {
          main()
          return
        }
        google.script.run
          .withSuccessHandler(htmlFragment => {
            $('#main').html(htmlFragment)
          })
          .getHtml(hash)
      }
      google.script.history.setChangeHandler(change)

      //Function to add Main page html
      function main() {
        $('#main').html(`
            <ul>
              <li><a href="#page1">Page1</a></li>
              <li><a href="#page2">Page2</a></li>
            </ul>`)
      }

      //Loads Main html from main function
      //Adds toggle to span to change to a Multiple page app
      $(() => {
        main()
        $('#type').on('click', () => {
          let hf = $('a').attr('href')
          if (!hf) return
          hf = hf.indexOf('#') + 1
          $('#type').text(hf ? 'Multiple' : 'Single')
          $('a').each((i, el) => {
            $(el).attr('href', (i, v) =>
              hf ? '?page=' + v.slice(1) : '#' + v.slice(6)
            )
          })
        })
      })
    </script>
  </body>
</html>

If I edit the URL manually and use following and then enter - I will get target page without problem. https://script.google.com/a/macros/5times.co.in/s/AKfycbyY7gR13A1C7a7SVtbYnCy_2TiMeeZWM1ggW134GMKTHOwLvjfnJsGEmtzSgYQmLLIsbQ/exec#page2

But If I use the home page and then click page1 or page2 link then nothing happen to the page. Even though the URL is correctly changed as expected. This is confusing to me. If I edit the URL again and change page1 to page2 and then enter it will work. So why it is not loading page1/2 when I click the page1/2 link on main page?

All the codes are copied above. Thank for your effort in advance.

Cooper
  • 59,616
  • 6
  • 23
  • 54
k.b
  • 157
  • 1
  • 2
  • 13
  • As far as I understand you are using webapps and there is an issue with regards to your deployment, can you please specify which error is showing up, in addition to the previous mentioned, it'd be helpful to have a small reproducible code so as to replicate this. – Jose Vasquez Apr 19 '21 at 13:39
  • The userCodePanel is the name in the console for Javascript on the html page. Also try backticks for formatting code and urls. It makes them much easier to read and keeps them from turning into links. [format code](https://meta.stackexchange.com/questions/22186/how-do-i-format-my-code-blocks) – Cooper Apr 19 '21 at 15:42
  • It's hard to understand how your url would appear to change without looking at your code. The benefit of taking the time to create a [mcve] is usually rewarded by either helping you to figure out your problem or providing the volunteers here with a focused and clear example of what you are asking. Many people just provide their entire code which is often met with no one wanting to wade through it all and thus it doesn't get read. – Cooper Apr 19 '21 at 15:48
  • Where is your doGet(e)? Without a doGet() or a doPost() your deployed webapp url won't know what to do. – Cooper Apr 19 '21 at 19:58
  • Here's a multiple page example I did: https://stackoverflow.com/a/46943386/7215091 – Cooper Apr 19 '21 at 20:02
  • Here's another: https://stackoverflow.com/a/55770563/7215091 – Cooper Apr 19 '21 at 20:03

0 Answers0