4

I have the following json returned from service:

{
"html": "<iframe width=\"480\" height=\"270\" src=\"https://www.youtube.com/embed/FQpUOimNvXA?feature=oembed\" frameborder=\"0\" allowfullscreen></iframe>"
}

How can I get src attribute value i.e. https://www.youtube.com/embed/FQpUOimNvXA?feature=oembed using javascript ?

2 Answers 2

5

Create a jQuery object from the iframe and obtain the src attribute:

var jsonString = {"html": "<iframe width=\"480\" height=\"270\" src=\"https://www.youtube.com/embed/FQpUOimNvXA?feature=oembed\" frameborder=\"0\" allowfullscreen></iframe>"}
var src = $(jsonString.html).attr("src");
$("#source").html(src);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="source"></div>

0
1

FIDDLE

var data = {
"html": "<iframe width=\"480\" height=\"270\" src=\"https://www.youtube.com/embed/FQpUOimNvXA?feature=oembed\" frameborder=\"0\" allowfullscreen></iframe>"
}

console.log(data.html);

var str = data.html;
var word = str.split(" ");
var word1 = word[3].split('"');
console.log(word1[1]);

I made split a couple of times i ended up with https://www.youtube.com/embed/FQpUOimNvXA?feature=oembed

1
  • yeah i know KAD has a better answer accept his @Mark
    – guradio
    Sep 17, 2015 at 6:29

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.