title: Running JavaScript in AMP
body: <p>I am a bit confused as to how JavaScript is suppposed to be run in an AMP page. </p>
  
  <p>I got as far as understanding that my JavaScript must be executed in an iframe. Such iframe has to be placed down in the page (75% at least from top) and has to be served through https. This does indeed work:</p>
  
  <pre><code>&lt;amp-iframe 
    width=300 
    height=300 
    sandbox="allow-scripts allow-popups allow-popups-to-escape-sandbox" 
    layout="responsive"
    frameborder="0" 
    src="https://localhost:8000/?p=myjs"&gt;
  &lt;/amp-iframe&gt;
  </code></pre>
  
  <p>In that page (<code>https://localhost:8000/?p=myjs</code>) I can freely run my js.</p>
  
  <p>My problem is the following though:</p>
  
  <p>How am I supposed to run my code against the document of the main page including the iframe?</p>
  
  <p>I tried accessing <code>window.parent.document</code> and that is blocked. (of course).</p>
  
  <p>Can anyone explain how AMP people think we can actually port pages to AMP if all our js gets killed? What is the recommended pattern to have our js run on an AMP page? Is there any such thing or is it just assumed that developers must dump all their code?</p>
  
  <p>Thanks</p>