简体   繁体   English

如何禁用自定义 AMP 页面中的浏览器后退按钮?

[英]How To Disable Browser Back Button In Custom AMP Page?

last time i put this custom disable browser back button (Javascript) in my AMP websites page ( websites ).上次我将此自定义禁用浏览器后退按钮 (Javascript) 放在我的 AMP 网站页面 ( websites ) 中。

I use this script to reduce the bounce rate in seo.我使用这个脚本来降低 seo 中的跳出率。 But after requesting indexing in google search console i got some problem with "There is a required attribute missing from the HTML tag" in this script.但是在谷歌搜索控制台中请求索引后,我在这个脚本中遇到了一些问题,“HTML 标记中缺少一个必需的属性”。

Does anyone know what is the solution to disable this browser back button script on AMP Pages?有谁知道在 AMP 页面上禁用此浏览器后退按钮脚本的解决方案是什么?

<script type = "text/javascript" > history.pushState(null, null); window.addEventListener('popstate', function(event) { history.pushState(null, null); }); </script>

By the way, my page is fully custom html AMP page, so all my css, html, scripts are concatenated inside index.html file.顺便说一句,我的页面是完全自定义的 html AMP 页面,所以我所有的 css、html、脚本都连接在 index.html 文件中。

Websites: luckysanto.com网站: luckysanto.com

Is it a valid AMP page?它是有效的 AMP 页面吗? As I can see your script is non-AMP so probably it's deleted by amp sanitizer.正如我所看到的,您的脚本是非 AMP 的,因此它可能已被 amp sanitizer 删除。 You have to run your custom JavaScript in a Web Worker in order to have a valid AMP page.您必须在 Web Worker 中运行自定义 JavaScript 才能获得有效的 AMP 页面。 Here is amp-script component documentation.这是amp-script组件文档。

Since you can only run JS in the web worker (in other words isolated DOM), you cannot manipulate anything outside of it, most likely browser history too.因为你只能在 web worker 中运行 JS(换句话说,隔离的 DOM),你不能操作它之外的任何东西,很可能也是浏览器历史记录。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM