• Page 1 of 1
  • 1
Forum moderator: bigblog  
uCoz Community » For Webmasters » Custom Solutions » Convert youtube url to emded
Convert youtube url to emded
Harina
Posts: 62
Reputation: 0

Message # 1 | 8:25 AM
i add another field on add entry of a file catalog and want a user to add a youtube video and paste a youtube link there then some script will convert that link to iframe embed. I have the code but will not work on my website and somewhere its working here

https://jsfiddle.net/8qt2xrx8/3/

Code
<script>
var embed = function(url) {
    var id = url.split("?v=")[1]; //sGbxmsDFVnE
    var embedlink = "https://www.youtube.com/embed/" + id; //https://www.youtube.com/embed/sGbxmsDFVnE
    document.getElementById("youtubevideo").src = embedlink;
}

embed("https://www.youtube.com/watch?v=sGbxmsDFVnE");
</script>
<iframe id="youtubevideo" width="560" height="315" frameborder="0" allowfullscreen></iframe>
Datecity
Posts: 42
Reputation: 0

Message # 2 | 8:49 AM
Code
<?if($OTHER1$)?>
<iframe id="$ID$Uvideo"  frameborder="0" allowfullscreen></iframe>

<script>
var embed = function(url) {
var id = url.split("?v=")[1];
var embedlink = "https://www.youtube.com/embed/" + id;
document.getElementById("$ID$Uvideo").src = embedlink;
}
embed("$OTHER1$");
</script>
<?endif?>
joexyz
JOE-vascript
Posts: 1770
Reputation: 78

Message # 3 | 12:30 PM
Harina, where exactly (which template) are you trying to use the code?

This code can handle multiple youtube url formats:

Code
<iframe id="video_U$ID$" width="560" height="315" frameborder="0" allowfullscreen></iframe>

<script type="text/javascript">
  var youtubeRegex = /^.*((youtu.be\/)|(v\/)|(\/u\/\w\/)|(embed\/)|(watch\?))\??v?=?([^#\&\?]*).*/;
  var url = '$OTHER1$';  // replace $ OTHER1 $ with the code of the link field
  var matches = url.match(youtubeRegex);
  var id = matches && matches[7].length === 11 ? matches[7] : 0;
  
  if (id) {
    var iframe = document.getElementById('video_U$ID$');
    iframe.src = 'https://www.youtube.com/embed/' + id;
  } else {
    document.write('Video link is invalid');
  }
</script>


links it can work with:


hey i'm joe and i do not work for the company anymore, please contact other staff or tech support
icon by ch-chau

sometimes i lurk here
Harina
Posts: 62
Reputation: 0

Message # 4 | 3:07 PM
bigblog, at file catalog appearance of entry and full entry page. I know someone in my country who told me you had discuss about helping my site site www.bendella.com but he got motor accident so he tell me do discuss further with you but you dont answer message.

Added (2019-04-12, 3:18 PM)
---------------------------------------------
Datecity, thank you you modify the code well its working. bigblog, has more advanced one we maybe use all that because hes is working better. biggrin biggrin

joexyz
JOE-vascript
Posts: 1770
Reputation: 78

Message # 5 | 6:28 PM
Quote Harina ()
he got motor accident

gosh, I hope he's alright, we had a car crash in our family too last week

Quote Harina ()
you dont answer message

you sent me a private message? I must've missed it, I don't really look at PMs. You can try contacting me on discord (if you have that), it's what I use most of the time

hey i'm joe and i do not work for the company anymore, please contact other staff or tech support
icon by ch-chau

sometimes i lurk here
Harina
Posts: 62
Reputation: 0

Message # 6 | 9:51 PM
Quote
gosh, I hope he's alright, we had a car crash in our family too last week


am sorry! Got paralysis.
Quote
you sent me a private message? I must've missed it, I don't really look at PMs. You can try contacting me on discord (if you have that), it's what I use most of the time


I dont know that! I can use whatsapp we talk i want my company to pay your ticket and hotel you come and teach our team to uCoz maybe a month.

Code
<iframe id="video_U$ID$" width="560" height="315" frameborder="0" allowfullscreen></iframe>

<script type="text/javascript">
  var youtubeRegex = /^.*((youtu.be\/)|(v\/)|(\/u\/\w\/)|(embed\/)|(watch\?))\??v?=?([^#\&\?]*).*/;
  var url = '$OTHER1$';  // replace $ OTHER1 $ with the code of the link field
  var matches = url.match(youtubeRegex);
  var id = matches && matches[7].length === 11 ? matches[7] : 0;
  
  if (id) {
    var iframe = document.getElementById('video_U$ID$');
    iframe.src = 'https://www.youtube.com/embed/' + id;
  } else {
    document.write('Video link is invalid');
  }
</script>


can this code work in vimeo?
joexyz
JOE-vascript
Posts: 1770
Reputation: 78

Message # 7 | 4:05 PM
Quote Harina ()
Got paralysis

That's very unfortunate and saddening to hear.

Quote Harina ()
I dont know that! I can use whatsapp

I don't use/like whatsapp. I mainly use Discord and Skype for communication, but mostly Discord.

Quote Harina ()
i want my company to pay your ticket and hotel you come and teach our team to uCoz

I don't think that will be necessary, but thank you.

Quote Harina ()
can this code work in vimeo?

it will not, this only works with youtube links.

hey i'm joe and i do not work for the company anymore, please contact other staff or tech support
icon by ch-chau

sometimes i lurk here
uCoz Community » For Webmasters » Custom Solutions » Convert youtube url to emded
  • Page 1 of 1
  • 1
Search: