1

I am trying to create an accelerated mobile page(AMP) using Javascript. The AMP validator shows an error called "Custom JavaScript is not allowed".

I have tried below code.

<!doctype html>
<html amp>

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,minimum-scale=1">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <meta name="amp-script-src" content="sha384-vk5WoKIaW_vJyUAd9n_wmopsmNhiy-L2Z-SBxGYnUkunIxVxAv_UtMOhba_xskxh">
    <title>Document</title>
    <link rel="canonical" href="/" />
    <script async src="https://cdn.ampproject.org/v0.js"></script>
    <script async custom-element="amp-script" src="https://cdn.ampproject.org/v0/amp-script-0.1.js"></script>
    <style amp-boilerplate>
        body {
            -webkit-animation: -amp-start 8s steps(1, end) 0s 1 normal both;
            -moz-animation: -amp-start 8s steps(1, end) 0s 1 normal both;
            -ms-animation: -amp-start 8s steps(1, end) 0s 1 normal both;
            animation: -amp-start 8s steps(1, end) 0s 1 normal both
        }

        @-webkit-keyframes -amp-start {
            from {
                visibility: hidden
            }

            to {
                visibility: visible
            }
        }

        @-moz-keyframes -amp-start {
            from {
                visibility: hidden
            }

            to {
                visibility: visible
            }
        }

        @-ms-keyframes -amp-start {
            from {
                visibility: hidden
            }

            to {
                visibility: visible
            }
        }

        @-o-keyframes -amp-start {
            from {
                visibility: hidden
            }

            to {
                visibility: visible
            }
        }

        @keyframes -amp-start {
            from {
                visibility: hidden
            }

            to {
                visibility: visible
            }
        }
    </style>
    <noscript>
        <style amp-boilerplate>
            body {
                -webkit-animation: none;
                -moz-animation: none;
                -ms-animation: none;
                animation: none
            }
        </style>
    </noscript>
</head>

<body>
    <amp-script script="local-script">
        <button>Hello amp-script!</button>
    </amp-script>
    <script target="amp-script" type="text/plain" id="local-script">
        console.log('js added')
    </script>
</body>

</html>

I need to find some possible solution to work AMP with Javascript. The AMP validator needs to be clean as it shows 1 error "Custom JavaScript is not allowed" which I am unable to find the cause from the above code.

Tales
  • 269
  • 3
  • 14
  • Hi, take a look [here](https://stackoverflow.com/questions/57828607/how-to-use-jquery-with-amp-script) I think that this question answers what you want. – KoKa Feb 04 '20 at 11:11
  • Have a look at the url: https://amp.dev/documentation/guides-and-tutorials/learn/validation-workflow/validation_errors/#custom-javascript-is-not-allowed OR https://github.com/bbc/simorgh/issues/885 OR https://stackoverflow.com/questions/36035733/best-way-to-include-custom-javascript-in-amp OR https://amp.dev/documentation/guides-and-tutorials/develop/custom-javascript/ – Prasad Wargad Feb 04 '20 at 11:14
  • I have updated the question, now I am trying to find it by javascript but it still shows one error – Tales Feb 04 '20 at 12:24
  • The actual issue was of my localhost server. The validation error was cleared when I added the code on remote server. Thanks for the replies. – Tales Feb 05 '20 at 12:37

0 Answers0