I have a javascript code that searches in a html page/content and replaces every youtube link with an iframe embedded link.
This works fine for normal youtube links like this:
https://www.youtube.com/watch?v=2xZL3WoBQzI
However, some of the video links in my html have an extra variable at the end of them which causes my JavaScript code to not work properly.
They are like this:
https://www.youtube.com/watch?v=2xZL3WoBQzI&t=15s
The issue is because of the &t=15s
This is my code:
$('.element').html(function(i, html) {
return html.replace(/(?:https:\/\/)?(?:www\.)?(?:youtube\.com|youtu\.be)\/(?:watch\?v=)?(.+)/g, '<iframe width="100%" src="https://www.youtube.com/embed/$1" frameborder="0" allowfullscreen></iframe>');
});
Could someone please advice on this issue?
Thanks in advance.