javascript - 如何将第三方插件与 AMP 集成
问题描述
我正在尝试将intlTelInput
插件集成到 AMP 页面中。该插件工作正常,但 AMP 抛出错误(不允许自定义 javascript)。
插件信息 https://github.com/jackocnr/intl-tel-input
为了更清楚,我附上了一个错误截图。
下面是代码片段。
<!doctype html>
<html ⚡ lang="en">
<head>
<meta charset="utf-8">
<meta name="amp-script-src" content="sha384-05IkdNHoAlkhrFVUCCN805WC_h4mcI98GUBssmShF2VJAXKyZTrO_TmJ-4eBo0Cy">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="canonical" href="self.html" />
<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>
<style amp-custom>
@import "https://cdnjs.cloudflare.com/ajax/libs/intl-tel-input/17.0.13/css/intlTelInput.css";
</style>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/intl-tel-input/17.0.13/js/intlTelInput.min.js" type="text/javascript"></script>
<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>
</head>
<body>
<div class="container">
<section class="todoapp">
<amp-script src="https://cdnjs.cloudflare.com/ajax/libs/intl-tel-input/17.0.13/js/intlTelInput.min.js" layout="container">
<input id="phone" name="phone" type="tel">
<button type="submit">Submit</button>
</amp-script>
<script type="text/javascript">
var input = document.querySelector("#phone");
window.intlTelInput(input, {
autoHideDialCode: false,
geoIpLookup: function(callback) {
$.get("https://ipinfo.io", function() {}, "jsonp").always(function(resp) {
var countryCode = (resp && resp.country) ? resp.country : "";
callback(countryCode);
});
},
initialCountry: "auto",
nationalMode: false,
});
</script>
</section>
</div>
</body>
</html>
解决方案
推荐阅读
- javascript - 如何通过 JS 或 JQuery 删除 html 中的代码
- uwp - Windows 10 开发者设置中的 PIN 码在哪里?
- c# - 仪表板背景图。网络mvc核心
- c++ - 链接库和头文件 g++
- powershell - Invoke-Command 在本地运行时是在当前范围内运行还是在子范围内运行?
- java - 如何直接从复制或分享 URL 中获取 Instagram 图片或视频 URL?
- c++ - std::make_unique 带有空指针?
- python - python 上的前向声明与使用 globals()
- javascript - 如何将对象的键和子键数组转换为指向某个属性值的链接?
- javascript - 为什么我的角色在我的 2D 横向卷轴中移动不顺畅?