0

I am trying to do

Here is the code inside my HTML

<iframe class="embed-responsive-item"  id="placeYoutubeVideo"
        style="display:none" src="#" style="display:none" allowfullscreen></iframe>

In jQuery I am trying to change the src of the video

var neww = 'https://youtu.be/NOubzHCUt48';
        $('#placeYoutubeVideo').prop('src', neww)

But it is throwing the following error:

Refused to display 'https://www.youtube.com/watch?v=NOubzHCUt48&feature=youtu.be' in a frame because it set 'X-Frame-Options' to 'SAMEORIGIN'.

How can I fix this?

If not possible is it possible to generate iframe with youtube url on click function?

help please.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Biz Dev B
  • 383
  • 1
  • 6
  • 18
  • This Possible duplicate: [How to set 'X-Frame-Options' on iframe?](http://stackoverflow.com/questions/27358966/how-to-set-x-frame-options-on-iframe) might help you understand your problem... – FirstOne Dec 28 '15 at 11:56

4 Answers4

1

Try this

<iframe class="embed-responsive-item" id="placeYoutubeVideo" src="#" allowfullscreen></iframe> 
<script> 
$(document).ready(function () { 
var neww = 'http://www.youtube.com/embed/NOubzHCUt48'; $('#placeYoutubeVideo').attr('src', neww); }); 
</script>

https://jsfiddle.net/vyt7gxwz/

HTTP -> HTTPS = ERROR (X-Frame-Options' to 'SAMEORIGIN)

HTTP -> HTTP = OK

HTTPS -> HTTPS = OK

HTTPS -> HTTP = ERROR (X-Frame-Options' to 'SAMEORIGIN)

0

Instead you can replaceWith

 var neww = 'https://youtu.be/NOubzHCUt48';
 var newContent = '<iframe class="embed-responsive-item"  id="placeYoutubeVideo" style="display:none" src="'+neww +'" style="display:none"  allowfullscreen></iframe>'

// Replace 'neww ' with your new URL

     $('#placeYoutubeVideo').replaceWith(newContent );
Anto S
  • 2,448
  • 6
  • 32
  • 50
  • Thanks, but am getting this error Uncaught TypeError: $(...).replace is not a function – Biz Dev B Dec 28 '15 at 12:04
  • Same error now 'Refused to display 'https://www.youtube.com/watch?v=NOubzHCUt48&feature=youtu.be' in a frame because it set 'X-Frame-Options' to 'SAMEORIGIN'.' – Biz Dev B Dec 28 '15 at 12:07
0

Try this

var neww = 'https://youtu.be/NOubzHCUt48';
iframe.setAttribute("src", neww);

Syntax

element.setAttribute(attributename,attributevalue)

Parameter Values

attributename   |  String   |  Required. The name of the attribute you want to add
attributevalue  |  String   |  Required. The value of the attribute you want to add

HTML DOM setAttribute() Method


EDIT 01

If you want add that to only one element

document.getElementsByID("placeYoutubeVideo").setAttribute("src", neww); 
Abdulla Nilam
  • 36,589
  • 17
  • 64
  • 85
0

X-Frame-Options: Sameorigin is used by YouTube to prevent clickjacking. You will need to embed the actual playlist.

Embed videos & playlists

Whamo12
  • 76
  • 4