It's no longer possible to use the YouTube rel parameter to prevent suggested videos from appearing

As announced in this document, it's no longer possible to disable related (YouTube) videos in iframe embeds using the rel parameter. This means that we can no longer use it to prevent suggested videos from appearing after an embedded video has come to an end. So what can we do if we don't want them?

EDIT:
A better alternative can be found here.


1. Using the loop parameter
As the loop parameter only works when used in conjunction with the playlist parameter, we should do something like the following in case of a single video:
<iframe style="position: relative; display: block; width: 50%; height: 50vh; margin: auto" src="http://www.youtube.com/embed/bKZbvluHcNo?playlist=bKZbvluHcNo&loop=1"></iframe>
That works: no related videos at the end of the video since it always starts all over again. (You will see related videos when you pause the video though, but they can be clicked away. As far as I know, there's nothing we can do about this new YouTube behavior).
Of course, this also works for 'real' playlists. In fact, it's the only good way of hiding related videos in playlists (see also below).

2. Using javascript
YouTube Api in the head:
<script src="http://www.youtube.com/player_api"></script>
Iframe in the body:
<iframe style="position: relative; display: block; width: 50%; height: 50vh; margin: auto" src="http://www.youtube.com/embed/bKZbvluHcNo?html5=1&enablejsapi=1" onload="my_player=new YT.Player(this ,{events: {'onStateChange':function(e){if(e.data === 0){my_player.stopVideo()}}}})"></iframe>
The name for the player (here: my_player) can be arbitrarily chosen.
 
For single videos, this method is better than the one described in (1) above since we don't need an artificial playlist here and a loop to hide related videos at the end of the video.
 
If we still want the loop, we can do (seekTo instead of stopVideo):
<iframe style="position: relative; display: block; width: 50%; height: 50vh; margin: auto" src="http://www.youtube.com/embed/bKZbvluHcNo?html5=1&enablejsapi=1" onload="my_player=new YT.Player(this ,{events: {'onStateChange':function(e){if(e.data === 0){my_player.seekTo(0)}}}})"></iframe>
That would create a real loop for a single video without artificial playlist.

3. When not to use javascript: (real) playlists
Don't use the latter loop-method though for a (real) playlist like this one:
<iframe style="position: relative; display: block; width: 50%; height: 50vh; margin: auto" src="http://www.youtube.com/embed/bKZbvluHcNo?html5=1&enablejsapi=1&playlist=Od8KGMQhpG0" onload="my_player=new YT.Player(this ,{events: {'onStateChange':function(e){if(e.data === 0){my_player.seekTo(0)}}}})"></iframe>
because at the end of the second video the player doesn't return to the first video but endlessly repeats the second one (unless we add &loop=1).
 
For a silimar reason, don't use this (stopVideo() instead of seekTo(0)):
<iframe style="position: relative; display: block; width: 50%; height: 50vh; margin: auto" src="http://www.youtube.com/embed/bKZbvluHcNo?html5=1&enablejsapi=1&playlist=Od8KGMQhpG0" onload="my_player=new YT.Player(this ,{events: {'onStateChange':function(e){if(e.data === 0){my_player.stopVideo()}}}})"></iframe>
because this stops the player at the end of the very first video (even if we add &loop=1).
 
So, as already said, the only good way to loop playlists in order to prevent related videos from appearing is the one described in (1) above.

4. Javascript: custom functions for preventing related videos to appear at the end of a single video
We might prefer custom functions in the onload for the iframe replacing the long lines given above: one for stopping a (single) video and one for looping it / making it return to the start (we have seen above that javascript is not the best way of 'doing it' for playlists):
<script>
function hide_related_stop()
{
my_player=new YT.Player(document.getElementById('the_ifr') ,{events: {'onStateChange':function(e){if(e.data === 0){my_player.stopVideo()}}}});
}
function hide_related_seek()
{
my_player=new YT.Player(document.getElementById('the_ifr') ,{events: {'onStateChange':function(e){if(e.data === 0){my_player.seekTo(0)}}}});
}
</script>
 
Usage:
(stop the video when it has come to an end)
<iframe id="the_ifr" style="position: relative; display: block; width: 50%; height: 50vh; margin: auto" src="http://www.youtube.com/embed/bKZbvluHcNo?html5=1&enablejsapi=1" onload="hide_related_stop()"></iframe>
 
or:
(loop the video)
<iframe id="the_ifr" style="position: relative; display: block; width: 50%; height: 50vh; margin: auto" src="http://www.youtube.com/embed/bKZbvluHcNo?html5=1&enablejsapi=1" onload="hide_related_seek()"></iframe>
 
Of course, when we use multiple iframes, we should have a unique id for each iframe and different names for the different players. Our functions hide_related_stop() and hide_related_seek() should be adapted to this situation. Here's an example-case (two iframes):
<script>
function hide_related_stop()
{
my_player1=new YT.Player(document.getElementById('the_ifr1') ,{events: {'onStateChange':function(e){if(e.data === 0){my_player1.stopVideo()}}}});
}
function hide_related_seek()
{
my_player2=new YT.Player(document.getElementById('the_ifr2') ,{events: {'onStateChange':function(e){if(e.data === 0){my_player2.seekTo(0)}}}});
}
</script>
 
<iframe id="the_ifr1" style="position: relative; display: block; width: 50%; height: 50vh; margin: auto" src="http://www.youtube.com/embed/bKZbvluHcNo?html5=1&enablejsapi=1" onload="hide_related_stop()"></iframe>
 
<iframe id="the_ifr2" style="position: relative; display: block; width: 50%; height: 50vh; margin: auto" src="http://www.youtube.com/embed/Od8KGMQhpG0?html5=1&enablejsapi=1" onload="hide_related_seek()"></iframe>

5. Conclusions
The most important conclusions that can be drawn from the preceding is that only in the case of single videos we can disable related videos without creating a loop (using javascript, see (2) above), that playlists need a loop (that is best created with the help of the YouTube loop parameter, see (3) above), and that YouTube has taken a very bad decision in removing the possibily of hiding related videos with the help of the rel parameter.
 
YouTube, what have you done to us!

Arie Molendijk, mesdomaines.nu.