Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Embedding Youtube video using iframe gives "Unsafe JavaScript attempt ... "

I'm trying to embed a YouTube video with this code:

<iframe width="425" height="319" frameborder="0" wmode="Opaque"allowfullscreen=""
      src="http://www.youtube.com/embed/8vJwFvFi4ZY?wmode=transparent">
</iframe>

and although it is working fine, but it gives this error in the console:

Chrome version 22.0.1229.94:

Unsafe JavaScript attempt to access frame with URL http://example.com/
from frame with URL http://www.youtube.com/embed/8vJwFvFi4ZY?wmode=transparent.
Domains, protocols and ports must match.

Firefox version 17.0:

Error: Permission denied to access property 'toString'

I searched around but I found that it is probably a YouTube issue and they should solve it,

The question is: how can I get rid of this error? (by any means, even by suppressing it.)

like image 471
AbdelHady Avatar asked Nov 29 '12 11:11

AbdelHady


People also ask

Can YouTube videos can be embedded using an IFrame?

The IFrame player API lets you embed a YouTube video player on your website and control the player using JavaScript.

What happens if you allow embedding on YouTube?

YouTube allows you to embed videos. You can add it to a specific page, making it easy to watch right away without ever leaving your website. Think of it as installing a flatscreen television on the walls of your website and being able to show your visitors what you want, when you want.

Should I allow embedding on YouTube videos?

In most cases, you'll want to embed videos. Embedding videos help improve video SEO and the searchability of your video content. But there's no harm in occasionally linking videos, especially for external content.

Why can't I embed a YouTube video?

If you receive the error message, "Embedding disabled on request” ,you have probably accidentally disabled embedding via YouTube. To grant permission again, follow these steps: Go to “Video Manager.” Select the appropriate video and click “Edit”.


1 Answers

You can’t stop it, at least not in any way I know (and I have tried a lot). There is a script in the iframe destination that tries to access your document, probably looking for global functions it can call to enable the API.

Another thing is that the error persists even when using their own iframe API: http://jsbin.com/izabed/1/edit

There is no harm in this, your video will work fine. But it looks kind of bold if you run it in a console. They should probably include this as a parameter, and at first I thought that this was the idea of the origin parameter, but it doesn’t make any difference.

It’s also worth noting that their own demo displays the same error (and others). Also, if you use the embed tag instead of iframe, it wont display any errors.

So you could do something like this to prevent the error in most desktop browsers:

if(haveflash) {
    // use <embed>
} else {
    // use iframe
}

Update

Most browsers no longer support flash, nor does Adobe. Unfortunately, this means that using <embed> is no longer a viable option.

like image 174
David Hellsing Avatar answered Sep 30 '22 18:09

David Hellsing