Failed to execute 'postMessage' on 'DOMWindow': target/origin mismatch http vs https

前端 未结 4 562
野的像风
野的像风 2020-12-06 07:54

I apologize up front as I\'m very confused by my problem. I\'m really in a bind because this is causing a problem on my production site.

I have a javascript player o

4条回答
  •  悲&欢浪女
    2020-12-06 08:30

    @sodawillow's answer is partially correct but I'd like to give the details to the solution and what caused my code to stop calling the .destroy() method to remove the youtube player.

    My site has a player which swaps out songs from various sites, one of them being Youtube. There can be different methods for removing a player depending on the type it is. My code checks for the existence of a youtube player and if passes the check then it uses the .destroy() method which only the youtube player has. The problem is that YouTube changed the names of some of the static variables on their player object. For example, if I created a player via:

    var player = new YT.Player('playlist-player', {
          playerVars: { 'autoplay': 1, 'fs': 0 },
          videoId: "gJ6APKIjFQY",
          events: {
          }
        })
    

    then there would be a variable player.L which held the string "player". So to check if the current player was a YouTube player and remove it I did this:

    if (player.L == "player") {
      player.destroy();
    } else {
    //handle the removal of the Soundcloud or Vimeo player.
    }
    

    Sometime recently Youtube changed the location of the string "player" to now reside at player.M. I could change the above code to check player.M instead of player.L and that would work but to try to avoid this issue in the future I instead have implemented:

    if (player.destroy) {
      player.destroy();
    } else {
    //handle the removal of the Soundcloud or Vimeo player.
    }
    

    As long as Youtube does not remove the .destroy() method unannounced this will not cause any issues.

    So in summary, the issue was as @sodawillow guessed, I was not using the .destroy() method to remove the Youtube player. The reason was because Youtube made some unannounced changes to their api, changing the location of some of the static variables.

提交回复
热议问题