Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
531 views
in Technique[技术] by (71.8m points)

javascript - History.replaceState() not working on Chrome (mobile browser)

The situation

After a user registers on our website, they receive an e-mail with a link to our homepage with verification token. Once a user clicks on the link, enters the page and sees a welcome modal. The token is silently removed from the url and history without the page being refreshed. This avoids users triggering a "Token already verified" message when pressing the back button or refreshing the page. When the user closes the welcome modal, the page is also refreshed to log them in.

We do this using history.replaceState({}, pageTitle, '/'), which should be supported on all browsers according to Mozilla's documentation.

The issue

All browsers on mobile and desktop follow this behavior, except Chrome on mobile, which completely ignores the function and leaves the token in the url. This means that when users close the welcome modal and the page refreshes to log them in, they see a "Token already verified" message.

I'm evading this by, instead of reloading the page, "redirecting" the user to the same url without the token after closing the welcome modal.

The question

Does Chrome browser on mobile support history.replaceState() and am I doing something wrong in my code or does Chrome not support this API on mobile?

question from:https://stackoverflow.com/questions/65887555/history-replacestate-not-working-on-chrome-mobile-browser

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...