本文介绍了如何重定向页面放大器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要将以下javascript代码调整为适用于amp页面.
I need to adapt the following javascript code to an amp page.
<select id="url"> <option value='home'>home</option> <option value='contact'>contact</option> </select> <input type="button" value='ir' onclick='ir()'> <script> function ir(){ var url=document.getElementById("url").value; location.href=url; } </script>有可能吗?
在文档中我找不到答案.
In the documentation I did not find the answer.
推荐答案您正在使用按钮和onclick函数,在AMP中,您可以使用锚标记<a href="Value">Value</a>并使用`amp-bind'
You are using button and onclick function, in place of this in AMP you can use anchor tag <a href="Value">Value</a> and change the url using `amp-bind'
您可以使用amp-bind实现目标
> 这是有效的URL
在标头中添加JS
<script async custom-element="amp-bind" src="cdn.ampproject/v0/amp-bind-0.1.js"></script>在正文中添加代码
<div class="wrapper"> <select on="change:AMP.setState({ url: event.value })"> <option value='home'>home</option> <option value='contact'>contact</option> </select> <a [href]="url" href="home">ir</a> </div>已更新-如果某人想更改选项时重定向而不是使用navigateTo操作
Updated - if some one want to redirect on option change than use navigateTo action
示例:
<select on="change:AMP.navigateTo(url=event.value)"> <option value="google">google</option> <option value="yahoo">yahoo</option> <option value="bing">bing</option> </select>更多推荐
如何重定向页面放大器?
发布评论