如何在AMP-HTML页面中加载外部页眉和页脚HTML [英] How to load external header and footer HTML in AMP-HTML pages

查看:114
本文介绍了如何在AMP-HTML页面中加载外部页眉和页脚HTML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将现有的HTML转换为AMP-HTML.在较旧的HTML中,我正在加载 footer header ,它们位于单独的HTML文件中,这些文件通过使用jquery进行加载,如以下代码中所述.

I am converting an existing HTML to AMP-HTML. In older HTML I am loading footer and header which are in separate HTML files which are loaded by using jquery as mentioned in the below code.

$("#divHeader").load('../header.html');

$("#divFooter").load('../footer.html');

这些HTML仅包含静态数据.有什么方法可以在AMP页面中添加这些HTML?我不能使用amp-iframe,因为amp-iframe不能在视口的前75%之内,并且必须距顶部600px,如本

These HTML have only static data. Is there any way to add these HTML in AMP pages? I cannot use amp-iframe because amp-iframe cannot be within first 75% of the viewport and has to be 600px away from the top as mentioned in this link.

推荐答案

AMP不能包含任何类型的外部样式表脚本.对于您的HTML文件,您可能已使用HTML部分加载.但是对于AMP页面,则不能包含该页面,而必须在AMP中显式地编写页眉和页脚

AMP cannot contain any type of external stylesheet or scripts. For your HTML file, you might have used the HTML partials to load. But in the case of AMP pages, you cannot include that, you have to explicitly write your header and footer in AMP

在官方文档此处中,在 HTML标记下标题,指定为

In the official doc here, under the HTML Tags heading it is specified that

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

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

这篇关于如何在AMP-HTML页面中加载外部页眉和页脚HTML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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