Iframe上传者权限

Mac*_*Mac 2 html javascript iframe jquery permission-denied

我在iframe中有这个文件上传器,但是当我将它嵌入到另一个网站时它不允许我,Firebug会显示以下错误:

< http://www.mywebsite.com > 允许从< http://www.myotherwebsite.com > 获取属性Window.document的权限.

来到这一行:

$('iframe', top.document).css('border', '1px green solid'); 
Run Code Online (Sandbox Code Playgroud)

上传完成后,我正试图用边框设置iframe的样式.

我看到其他问题,解决方案是制作服务器端代理,我不知道如何使代理工作并允许jQuery执行.

干杯.

赏金补充道.

jmo*_*253 5

服务器端代理可以帮助您克服此问题.虽然浏览器只能使用相同的域对其服务器进行AJAX调用,但服务器本身可以无限制地调用任何其他服务器.

假设您需要向Yahoo的Weather API发出AJAX请求.由于相同的域策略,您无法从www.example.com向www.yahoo.com提出请求,因此解决方法是首先向您的服务器发出呼叫,然后让您的服务器向Yahoo发出请求.下面是一个代理的例子:

请求:http://www.example.com/weather.php? zip = 97015

<? // Yahoo Weather proxy

$zip_code = $_REQUEST["zip"];

// default to Portland, OR for testing
if($zip_code == null || $zip_code == '')
    $zip_code = "97206";

// delegate request to the other server, circumventing the same-domain policy.
$request = "http://weather.yahooapis.com/forecastrss?p=".$zip_code;

$response = file_get_contents($request);

// Retrieve HTTP status code
list($version,$status_code,$msg) = explode(' ',$http_response_header[0], 3);


// Check the HTTP Status code
switch($status_code) {
    case 200:
            // Success
            break;
    case 503:
            die('Your call to Yahoo Web Services failed and returned an HTTP status of 503. That means: Service unavailable. An internal problem prevented us from returning data to you.');
            break;
    case 403:
            die('Your call to Yahoo Web Services failed and returned an HTTP status of 403. That means: Forbidden. You do not have permission to access this resource, or are over your rate limit.');
            break;
    case 400:
            // You may want to fall through here and read the specific XML error
            die('Your call to Yahoo Web Services failed and returned an HTTP status of 400. That means:  Bad request. The parameters passed to the service did not match as expected. The exact error is returned in the XML response.');
            break;
    default:
            die('Your call to Yahoo Web Services returned an unexpected HTTP status of:' . $status_code);
}


echo $response;
?>
Run Code Online (Sandbox Code Playgroud)

现在,在您的情况下,您希望在文件上传完成后设置iframe的样式.一个简单的解决方案是轮询父文档的服务器并让代理轮询上传服务器,直到找到该文件.找到文件后,响应可用于调用更改iframe样式的JQuery代码.

为了使代理概念起作用,您嵌入上传者的每个网站都需要部署自己的同域代理,这将检查您的上传网站是否存在该文件,然后将该响应返回给客户端.

父文档还将以某种方式知道正在上载的文件的名称.由于域策略相同,您可能无法确定文件名,这在使用代理检查文件是否存在时会带来挑战.你怎么知道你在检查什么?