history.pushState不会更新"share ..."的网址Chrome浏览器上的按钮 [英] history.pushState does not update url for "share ..." button on mobile Chrome

查看:164
本文介绍了history.pushState不会更新"share ..."的网址Chrome浏览器上的按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用history.pushState更新URL,如下所示:

I am using history.pushState to update URL as below:

var state = {url: newLocation};
window.history.pushState(state, pagetitle, newLocation);    

在Mobile Chrome上,网页URL(在URL栏上)和标题确实得到了预期的更新.但是,当单击Chrome菜单上的共享..."按钮时,将改为共享旧的URL(在调用history.pushState之前).我是否缺少任何东西,该如何解决?谢谢!

On Mobile Chrome, the webpage URL (on the URL bar) and title do get updated as expected. But when clicking on the "Share..." button on the Chrome menu, the old URL (before calling history.pushState) is shared instead. Am I missing anything and how can I fix it? Thanks!

推荐答案

我发现rel ="canonical"网址也应更新.

I found out that the rel="canonical" url should also be updated.

$('link[rel="canonical"]').attr('href', newLocation);

这篇关于history.pushState不会更新"share ..."的网址Chrome浏览器上的按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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