None
None

Reputation: 5670

Appending src to iframe through jquery fails

I am appending an iframe to my html through jquery. Code is like this.

function setImageUrl(imgname) {

   $(".large-image iframe").remove();
    var u = '<iframe width="560" id="iframevideo" height="315" src="#" frameborder="0" allowfullscreen></iframe>';
    $(".large-image").append(u);   
    document.getElementById('iframevideo').setAttribute("src", imgname); 
return true;

} Parameter imgname is coming correctly and it is the intended Iframe src But this always produces a blank iframe. like this one

enter image description here

On the other hand, If i hardcoded the src everything works fine.So I assume the issue is some where I am setting src.I have tried different methodes ,but nothing works.

Upvotes: 0

Views: 252

Answers (2)

Neha
Neha

Reputation: 1548

There is working demo ..

function setimage () {
  $("#oldframe").remove();
  $("#main").append("iframe tag ");
  $('#newframe').attr('src', 'imgurl');
}

Demo

Upvotes: 0

user2587132
user2587132

Reputation:

Try

 document.getElementById('iframevideo').src=imgname;

or

$('#iframevideo').attr('src', imgname);

Upvotes: 1

Related Questions