---
title: "chrome中页面有跨域iframe出现Adobe Flash Player安全性设置窗口"
author: "AS3"
date: "2011-06-22T01:12:17Z"
tags: []
categories: ["编程语言"]
slug: "chrome-iframe-adobe-flash-player"
draft: false
lastmod: "2011-06-22T01:12:17Z"
id: 1100384
url: "https://as3.iteye.com/blog/1100384"
---

[http://bbs.9ria.com/viewthread.php?tid=85933&extra=page%3D1%26amp%3Borderby%3Ddateline%26amp%3Bfilter%3D2592000](http://bbs.9ria.com/viewthread.php?tid=85933&extra=page%3D1%26amp%3Borderby%3Ddateline%26amp%3Bfilter%3D2592000)

 

 

 

 

 

 

 

 

*本帖最后由 bcpxqz 于 2011-6-16 17:38 编辑*

a.html和b.html不同域,a.html用iframe嵌入b.html，在chrome中有时候会出现Adobe Flash Player安全性设置窗口（图1），在console面板中可以看到，四条"Unsafe JavaScript attempt to access frame with URL"错误，但如果你看图2，就会发现，

1. "Unsafe JavaScript attempt to
2. access frame with URL http://a.com/adtest/39iframe/d1.html from frame
3. with URL http://a.com/adtest/39iframe/d1.html. Domains, protocols and
4. ports must
5. match."

*复制代码*

是同一页面。我想知道问题出在哪里？在其他ie,firefox,safari,opera里面测试不会出现这个设置窗口，在google code上也有讨论：[http://t.cn/aK3flf](http://t.cn/aK3flf)[http://t.cn/aK3flV](http://t.cn/aK3flV) 。  
![](http://bbs.9ria.com/attachments/month_1106/110616141525e7e4703026f324.gif)  
![](http://bbs.9ria.com/attachments/month_1106/1106161415430e2ec5a0b2ec6b.gif)  
chrome:10.0.648.45  
flash player:10,2,154,12

代码如下：  
a.htm页面结构

01. &lt;embed id="test1" name="test1" width="100" height="100"
02. type="application/x-shockwave-flash"
03. pluginspage="http://www.macromedia.com/go/getflashplayer"
04. allowscriptaccess="always" allowfullscreen="true" quality="high"
05. menu="false" wmode="transparent" src="blank.swf?num=outer"&gt;
06. &lt;iframe
07. width="100" scrolling="no" height="100" frameborder="0"
08. allowtransparency="true" marginheight="0" marginwidth="0"
09. src="http://b.com/b.html" name="iframe1"
10. id="iframe1"&gt;&lt;/iframe&gt;

*复制代码*

其中blank.swf中  
import flash.external.ExternalInterface;  
ExternalInterface.call("console.info",str);

Iframe b.html页面结构

1. &lt;embed id="AC86\_5500" name="AC86\_5500" width="100"
2. height="100" type="application/x-shockwave-flash"
3. pluginspage="http://www.macromedia.com/go/getflashplayer"  allowfullscreen="true"
4. quality="high" menu="false" wmode="transparent"
5. src="blank1.swf"&gt;

*复制代码*

其中blank1.swf，没有引入flash.external.ExternalInterface，是个空flash

*本帖最后由 ticore 于 2011-6-17 18:59 编辑*

[http://blog.richmediaplus.com/20 ... omain-inject-issue/](http://blog.richmediaplus.com/2011/06/js-cross-domain-inject-issue/)

反覆測試之後，將問題簡化如下：

1\. a.com 下的 HTML 網頁，包含一個 b.com 來的 iframe 網頁  
2\. b.com iframe 網頁內使用 javascript touch 一下 window.top.location  
3\. a.com 在 onload 完成後，動態建立一 Flash 物件  
4\. Flash 物件內透過 ExternalInterface 呼叫任何 Javascript Function  
5\. 得到以下錯誤訊息

SecurityError: Error #2060: 執行程序安全性違規：ExternalInterface 呼叫者[http://a.com/flash.swf](http://a.com/flash.swf) 無法存取 \[object]。  
at flash.external::ExternalInterface$/\_initJS()  
at flash.external::ExternalInterface$/call()  
at flash\_fla::MainTimeline/doCallJs()

已經簡化成這樣，很明顯問題是出在 javascript window.top.location 物件上  
想要避免該問題，只要在主頁上一載入立即搶先 touch window.top.location 就好了

在測試過程中，還發現另一個更嚴重的問題  
跨域的 iframe 能夠透過原型鍊 prototype 插入任意 function 到 location 物件上  
讓 top window 頁面呼叫並傳遞任何物件  
不受跨網域安全性的限制