2012-05-21 42 views
6

我有一個簡單的HTML網站與嵌入式Flash文件和SWFobject使用它。iFrame內的SWFobject:跨域的東西?

此網站是iframe的src。如果我打開與它的iframe控制檯告訴我的網站...

Unsafe JavaScript attempt to access frame with URL file:///experiment/iframe- 
test/index.html from frame with URL http://localhost.lan/embed/GYZA. Domains, 
protocols and ports must match. -> swfobject.js 

我不知道父窗口(在它的iframe)已與iframe中的swfobjet辦?因此,如上所述,swfobject用於將flash嵌入到加載到iframe的子頁面中。 iframe-test/index.html網站只是...

<body> 
    <iframe src="http://localhost.lan/embed/GYZA" width="100%" height="100%" frameborder="0" allowfullscreen></iframe> 
</body> 

...就可以了。而已。爲什麼我有一個unsafe javascript attempt here

有關於此的任何想法?先謝謝你。

更新:嗯,我只是認識到,這發生在Youtube和Vimeo以及他們的嵌入式播放器。我正在使用Chrome控制檯,並且Youtube和Vimeo發生同樣的錯誤。

回答

0

不知道現在是否有任何用處,但錯誤是因爲file:///experiment/iframe-test/index.htmlhttp://localhost.lan/embed/GYZA被瀏覽器視爲兩個不同的域,所以瀏覽器的跨域策略認爲這是不安全的。根據用戶擁有的瀏覽器,這可能是不安全的 - 您正在加載的遠程頁面可能包含有害腳本,可能會破壞當前正在查看的頁面,或嘗試竊取各種信息。你可以找到更多信息here

0

我剛剛驗證了Matt的更新問題。

每當一個flash對象被嵌入在跨域iframe中時,它將引發跨域異常。 Youtube和Vimeo都是如此。

例如,看看這個的jsfiddle具有嵌入的iFrame:http://jsfiddle.net/bkCdB/

<object width="420" height="315"><param name="movie" value="http://www.youtube.com/v/6V_DsL1x1uY?version=3&amp;hl=en_US"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/6V_DsL1x1uY?version=3&amp;hl=en_US" type="application/x-shockwave-flash" width="420" height="315" allowscriptaccess="always" allowfullscreen="true"></embed></object>