I'm working importing a rss feed via javascript from a blog and using it to display elements to a mobile app, so DOM manipulation is not an option.
I have a json parsed rss element that is a blog post that could contain one or more youtube video iframes, formated like this: <iframe src="//www.youtube.com/embed/0nvGQLnKg4Q" height="360" width="480" allowfullscreen="" frameborder="0"></iframe>
What I need is first get the src
from iframe, store it into a variable to get the video code, then replace the <iframe...></iframe>
to something like <a href="http://youtube.com/watch?v=YOUTUBEID"><img src="http://img.youtube.com/vi/YOUTUBEID/1.jpg" width="100%" /></a>
The solutions I found were all PHP solutions and I have not been able to transpose them to Javascript. Reference:
- PHP Regular expression to remove iframe (which can be used to replace)
- Get URL from iframe using PHP Regex
I tried so far using javascript function
string.replace('.../g')
But no luck using exactly the same regexes from PHP. Besides, I need that to be made on all the iframes that could appear in my string, not only one or the first. What I was trying is basically like this guy was. But the answer to him (manipulating DOM) is not an option for me.
Can anybody help me? Thanks in advance