0

I'm trying to get URL of background image for .av-video-player-bg inside this iframe:

<iframe src="http://www.gamespot.com/videos/embed/6425430/"></iframe>

I've tried

$("iframe").contents().find('.av-video-player-bg').css('background-image');

But I get this error:

Failed to read the 'contentDocument' property from 'HTMLIFrameElement': Blocked a frame with origin "http://www.gamespot.com" from accessing a cross-origin frame.

01000110
  • 282
  • 1
  • 3
  • 16

1 Answers1

4

If the domain of the iframe is not the same as the domain of the parent page, you will not be able to manipulate its content or get info about it due to the same origin policy

If they're different domains but you have control over its content (that is, you can add code to it), you can use Postmessaging to do what you are trying to do. Simply add a listener within the iframe's content which tells it when to fire off this change.

From looking at the domain however (gamespot) I imagine this is not your page so there isn't much you can do

Pabs123
  • 3,385
  • 13
  • 29
  • It's not mine. I want to embed some of videos in my page and I wanted to use a thumbnail of the video! Thanks for your reply! ^_^ – 01000110 Jan 05 '17 at 17:20