One solution to the problem of YouTube not playing properly when returning to a page using the browser’s back button is to use the onPlayerStateChange event
to play the video.
The onPlayerStateChange event
is triggered when the state of the YouTube player changes (for example, when the video is played or paused). This event can be used to control the playback of videos.
The specific code is as follows
function onPlayerStateChange(event) {
if (event.data == YT.PlayerState.CUED) {
event.target.playVideo();
}
}
This code starts playing the video when the video is in the queued (CUED) state.