Replace youtube tags with iframe tags

Go down

Replace youtube tags with iframe tags

Post by Luffy on May 16th 2016, 2:05 pm

Hello dear all,

I want a code for my editor that will replace the youtube tags with the iframes tags.
What i mean is:
When i want to add a youtube video in my posts i add it through the youtube icon and it takes the part after the / and adds it in [youtube] tags. Like this:
Code:
[youtube]c7nRTF2SowQ[/youtube]


Now those c7nRTF2SowQ are the key letters for the iframe too. So what i want is a code that will replace
Code:
[youtube]
with
Code:
<iframe width="560" height="315" src="https://www.youtube.com/embed/
and
Code:
[/youtube]
with
Code:
" frameborder="0" allowfullscreen></iframe>

Is there any code that will help me to that?



The alternative way would be a code that will replace the [youtube] tags after the post was sent and change them into the iframe tags i wrote above.

Any of these would be perfect!!

Thanks for your time and much appreciation for those who help!


My forum details:
Forum Link: http://www.thinktankforum.net
Forum Version: Phpbb3


Luffy :rose:


Last edited by Luffy on May 16th 2016, 6:14 pm; edited 1 time in total
avatar
Luffy
Manager
Manager

Male Posts : 5371
Reputation : 581
Language : Greek, English
Location : Greece

https://www.crossroadz.net

Back to top Go down

Re: Replace youtube tags with iframe tags

Post by Ange Tuteur on May 16th 2016, 4:45 pm

@Luffy try installing the following script in all the pages.
Code:
$(function() {
  for (var a = $('embed[src*="youtube"]'), i = 0, j = a.length; i < j; i++) {
    a[i].insertAdjacentHTML('beforebegin', '<iframe width="560" height="315" src="' + a[i].src + '" frameborder="0" allowfullscreen></iframe>');
    a[i].parentNode.removeChild(a[i]);
  }
});
It'll replace the embed elements with iframes.
avatar
Ange Tuteur
Forumaster

Male Posts : 13195
Reputation : 2910
Language : EN10, FR5, JA5
Location : Macungie, PA

https://github.com/SethClydesdale

Back to top Go down

Re: Replace youtube tags with iframe tags

Post by Luffy on May 16th 2016, 6:15 pm

Thank you @Ange Tuteur. That was exactly what i wanted! Smile



avatar
Luffy
Manager
Manager

Male Posts : 5371
Reputation : 581
Language : Greek, English
Location : Greece

https://www.crossroadz.net

Back to top Go down

Re: Replace youtube tags with iframe tags

Post by brandon_g on May 16th 2016, 6:29 pm

Thanks again for the help Ange. Smile

Topic solved and archived ~ brandon_g


Remember to mark your topic when a solution is found.
avatar
brandon_g
Support Moderator
Support Moderator

Male Posts : 6770
Reputation : 619
Language : English
Location : USA

http://broadcastingduo.forumotion.com/

Back to top Go down

Re: Replace youtube tags with iframe tags

Post by brandon_g on May 24th 2016, 12:55 pm

Topic re-opened on topic starter request ~ brandon_g


Remember to mark your topic when a solution is found.
avatar
brandon_g
Support Moderator
Support Moderator

Male Posts : 6770
Reputation : 619
Language : English
Location : USA

http://broadcastingduo.forumotion.com/

Back to top Go down

Re: Replace youtube tags with iframe tags

Post by Luffy on May 24th 2016, 1:10 pm

Hello and thank you brandon for re-opening the topic,

So the code @Ange Tuteur gave me works fine but it's not actually the one i posted on the first post.
The iframe on the first post has a src of "https://www.youtube.com/embed/Video Url" and the rest.. The code i have now simple changes the simple youtube frame to the iframe with that width. Is there any way we could change it to the actual iframe because when i tried to add the src in the js it showed me an error to the video. I suppose it's the "embed" word in the link (?) because it replaces the embed (?) Think

Thanks for your help! Smile



avatar
Luffy
Manager
Manager

Male Posts : 5371
Reputation : 581
Language : Greek, English
Location : Greece

https://www.crossroadz.net

Back to top Go down

Re: Replace youtube tags with iframe tags

Post by Luffy on May 29th 2016, 5:20 pm

Bump.



avatar
Luffy
Manager
Manager

Male Posts : 5371
Reputation : 581
Language : Greek, English
Location : Greece

https://www.crossroadz.net

Back to top Go down

Back to top


 
Permissions in this forum:
You cannot reply to topics in this forum