发布商需要什么才能编写与 amp-story 中的事件挂钩的代码?
What is required for publishers to write code that hooks into events in amp-story?
例如,HTML DOM 事件允许 JavaScript 在 HTML 文档中的元素上注册不同的事件处理程序。
事件通常与函数结合使用,函数不会在事件发生前执行(比如用户点击按钮)。
好处
Although there’s a lack of good documentation, adding a function that takes parameters (i.e. Function_Name(Parameter)) to one of JavaScript’s standard ‘On’ events (i.e. ‘OnClick‘ or ‘onKeyDown‘) is relatively simple for JavaScript coders. Advanced programmers might refer to this as dynamic runtime event assignment with functions using parameters passed.
Let’s say we have a text area field on a web page, and we want to execute some function every time they make a keystroke inside that field. In our real world example, we wanted to count the number of characters, so we could let the user know how close they were to the limit, and warn them when they exceed the limit. To capture keystrokes, we need to hook into JavaScript’s ‘onKeyUp‘ and ‘onKeyDown‘ events.
Experienced JavaScript developers know that the easiest way to add these hooks is to include them in the HTML for the textarea, like so:
目前对使用 JavaScript 创作页面的 AMP 无效。见How AMP works,具体为:
AMP pages can’t include any author-written JavaScript. Instead of using JavaScript, interactive page features are handled in custom AMP elements. The custom AMP elements may have JavaScript under the hood, but they’re carefully designed to make sure they don’t cause performance degradation.
下一段接着说:
While third-party JS is allowed in iframes, it cannot block rendering. For example, if third-party JS uses the super-bad-for-performance document.write API, it does not block rendering the main page.
但是,amp-story
特别不允许作者指定的 iframe。
因此,我认为您在这里提出的要求在 amp-story
的当前状态下是不可能的。
例如,HTML DOM 事件允许 JavaScript 在 HTML 文档中的元素上注册不同的事件处理程序。
事件通常与函数结合使用,函数不会在事件发生前执行(比如用户点击按钮)。
好处
Although there’s a lack of good documentation, adding a function that takes parameters (i.e. Function_Name(Parameter)) to one of JavaScript’s standard ‘On’ events (i.e. ‘OnClick‘ or ‘onKeyDown‘) is relatively simple for JavaScript coders. Advanced programmers might refer to this as dynamic runtime event assignment with functions using parameters passed.
Let’s say we have a text area field on a web page, and we want to execute some function every time they make a keystroke inside that field. In our real world example, we wanted to count the number of characters, so we could let the user know how close they were to the limit, and warn them when they exceed the limit. To capture keystrokes, we need to hook into JavaScript’s ‘onKeyUp‘ and ‘onKeyDown‘ events.
Experienced JavaScript developers know that the easiest way to add these hooks is to include them in the HTML for the textarea, like so:
目前对使用 JavaScript 创作页面的 AMP 无效。见How AMP works,具体为:
AMP pages can’t include any author-written JavaScript. Instead of using JavaScript, interactive page features are handled in custom AMP elements. The custom AMP elements may have JavaScript under the hood, but they’re carefully designed to make sure they don’t cause performance degradation.
下一段接着说:
While third-party JS is allowed in iframes, it cannot block rendering. For example, if third-party JS uses the super-bad-for-performance document.write API, it does not block rendering the main page.
但是,amp-story
特别不允许作者指定的 iframe。
因此,我认为您在这里提出的要求在 amp-story
的当前状态下是不可能的。