Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to trigger else clause in an onload event?
    primarykey
    data
    text
    <p>I have the <code>Comments</code> handle in my Google App Engine app to display the comments. I want to stop the page from loading if the user (defined as "chooser" here) is not in <code>localStorage</code>.</p> <p>I get the first 2 alerts: <code>"load event"</code> and <code>chooser: "undefined"</code>. Since "chooser" is undefined I expect the else clause to trigger but I don't get the alert in else clause.</p> <p>Also, the first item in ordered list is displayed but not the rest. So I assume there is an issue with loading of the page. How can I fix this?</p> <pre><code>class Comments(webapp.RequestHandler): def get(self): self.response.out.write(""" &lt;html&gt; &lt;head&gt; &lt;title&gt;Choices&lt;/title&gt; &lt;script type="text/javascript"&gt; function showChoices () { alert("load event"); var chooser = localStorage.getItem("chooser"); alert("chooser: " + chooser); if (chooser) { document.getElementById("topten").style.display="inline"; } else { alert("else triggers"); document.write("get an invitation"); } } window.onload = showChoices; &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;div class="content"&gt;""") #python code: query = Users.all() e = query.fetch(10) self.response.out.write("""&lt;ol&gt;""") for item in e: self.response.out.write(""" &lt;div id="topten" class="title" style="display:none"&gt; &lt;li&gt;%s (&lt;span class="small"&gt;%s&lt;/span&gt;)&lt;/li&gt; &lt;/div&gt; &lt;hr&gt;&lt;br /&gt;""" % tuple([item.choice, item.owner])) self.response.out.write("""&lt;/ol&gt;""") self.response.out.write(""" &lt;/div&gt; &lt;/body&gt; &lt;/html&gt;""") </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload