在 AMP 页面中添加 Javascript [英] Add Javascript in AMP Pages

查看:30
本文介绍了在 AMP 页面中添加 Javascript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请帮助我了解如何在 AMP(加速移动页面)中添加 javascript.我的要求是我在 URL 中得到一个 ID.例如 localhost:8080/home?id=1.我想在我的 html 文件中访问该 ID.

Please help me understand how to add javascript in the AMP (Accelerated Mobile Pages). My requirement is I get an ID in URL. For example localhost:8080/home?id=1.I would like to access that id in my html file.

或者请让我知道如何添加任何 javascript 文件.

or else please let me know how to add any javascript file.

谢谢.

推荐答案

很遗憾,您无法在 AMP 中添加任意脚本.来自 规范,在HTML 标签"下,标签 script:

Unfortunately, you cannot add arbitrary scripts in AMP. From the specification, under "HTML Tags," for the tag script:

禁止,除非类型为 application/ld+json.(可以根据需要添加其他不可执行的值.)例外是用于加载 AMP 运行时的强制脚本标签和用于加载扩展组件的脚本标签.

Prohibited unless the type is application/ld+json. (Other non-executable values may be added as needed.) Exception is the mandatory script tag to load the AMP runtime and the script tags to load extended components.

因此,如果您想使用 AMP 中的 JavaScript,则必须使用 AMP 的预定义 components.我没有看到可以执行您想要的操作的组件.

So, if you want to use JavaScript from AMP, you have to use AMP's predefined components. I don't see a component that does what you want.

这篇关于在 AMP 页面中添加 Javascript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆