|
|
Forum moderator: bigblog |
uCoz Community For Webmasters Custom Solutions Convert youtube url to emded |
Convert youtube url to emded |
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> |
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?> |
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: Code https://www.youtube.com/watch?v=VIDEO_ID&feature=feedrec_grec_index https://www.youtube.com/user/CHANNEL_NAME#p/a/u/1/VIDEO_ID https://www.youtube.com/v/VIDEO_ID?fs=1&hl=en_US&rel=0 https://www.youtube.com/watch?v=VIDEO_ID#t=TIMECODE (although timecode will be ignored) https://www.youtube.com/embed/VIDEO_ID?rel=0 https://www.youtube.com/watch?v=VIDEO_ID https://u.to/XF8bFQ 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 |
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) |
gosh, I hope he's alright, we had a car crash in our family too last week 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 |
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? |
That's very unfortunate and saddening to hear. I don't use/like whatsapp. I mainly use Discord and Skype for communication, but mostly Discord. I don't think that will be necessary, but thank you. 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 |
| |||
| |||