The forum of the forums
Welcome to the Official Support Forum of Forumotion!

To take full advantage of everything offered by our forum, please log in if you are already a member, or join our community if you've not yet.



Create a free forum like this one.

Replace youtube tags with iframe tags

View previous topic View next topic 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

Luffy
Manager
Manager

Male Posts : 4260
Reputation : 424
Language : Greek, English
Location : Greece

http://helpgr.forumgreek.com/forum

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.

Ange Tuteur
Forumaster

Male Posts : 13028
Reputation : 2704
Language : EN10, FR5
Location : Pennsylvania

http://fmdesign.forumotion.com

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






Luffy
Manager
Manager

Male Posts : 4260
Reputation : 424
Language : Greek, English
Location : Greece

http://helpgr.forumgreek.com/forum

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.

brandon_g
Support Moderator
Support Moderator

Male Posts : 5362
Reputation : 489
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.

brandon_g
Support Moderator
Support Moderator

Male Posts : 5362
Reputation : 489
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 "http://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






Luffy
Manager
Manager

Male Posts : 4260
Reputation : 424
Language : Greek, English
Location : Greece

http://helpgr.forumgreek.com/forum

Back to top Go down

Re: Replace youtube tags with iframe tags

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

Bump.






Luffy
Manager
Manager

Male Posts : 4260
Reputation : 424
Language : Greek, English
Location : Greece

http://helpgr.forumgreek.com/forum

Back to top Go down

View previous topic View next topic Back to top


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