1

On my WordPress blog in default mode I have a <canvas> where I draw a chart with ChartJS. I've just downloaded the AMP plugin, run the Google AMP Test tool, and it says:

Fix the following issue
Prohibited or invalid use of HTML Tag
The tag 'canvas' is disallowed.

How do you go about fixing this? Is there any way to do JavaScript with AMP?

2

You can't run your own JavaScript when using AMP, that defeats the purpose of AMP. Instead, you can iframe your external content using the amp-iframe element.

  1. Add the amp-iframe JS to the head.

    <script async custom-element="amp-iframe"
      src="https://cdn.ampproject.org/v0/amp-iframe-0.1.js"></script>
    
  2. Add the amp-iframe element where you want your iframe to go.

    <amp-iframe width="200" height="100"
      sandbox="allow-scripts allow-same-origin" layout="responsive"
      src="https://example.com/"></amp-iframe>
    

A full guide to using amp-iframe is available at:

| improve this answer | |
  • AMP sounds awful. – Stephen Ostermiller Jun 23 '17 at 19:07
  • Unfortunately, my blog does not support https, which Google requires for AMP, but fortunately my chart is inserted via a custom [graph] tag, and it has fallback functionality for <noscript> and sharing tools, so I've tweaked the code to always output the static JPG (drawn using an ancient PHP library) when rendering to AMP, so now we cleanly pass the Google check. – Ken Y-N Jun 25 '17 at 23:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.