我在iframe中有这个文件上传器,但是当我将它嵌入到另一个网站时它不允许我,Firebug会显示这个错误:
拒绝[http://www.mywebsite.com](http://www.mywebsite.com/)从[http://www.myotherwebsite.com](http://www.myotherwebsite.com/)获取属性Window.document的权限。
这句话的意思是:
$('iframe', top.document).css('border', '1px green solid'); 当上传完成后,我试图用边框对iframe进行样式化。
我看到了其他问题,解决方案是让服务器端代理,我不知道如何使它的代理工作,并允许jQuery执行。
干杯。
赏金补充说。
发布于 2011-02-07 08:08:05
服务器端代理可能会帮助您解决这个问题。虽然浏览器只能使用相同的域对其服务器进行AJAX调用,但服务器本身可以不受限制地调用任何其他服务器。
假设您需要向Yahoo的天气API发出AJAX请求。由于使用相同的域策略,您无法从www.example.com向www.yahoo.com发出请求,因此解决方法是先调用服务器,然后让服务器向雅虎发出请求。下面是代理的一个例子,它就是这样做的:
请求: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;
?>现在,在您的例子中,您希望在文件上传完成时对iframe进行样式化。一个简单的解决方案是轮询父文档的服务器,并让代理轮询您的上传服务器,直到找到该文件。找到文件后,可以使用响应来调用更改iframe样式的JQuery代码。
为了使代理概念有效,您嵌入上传器的每个网站都需要部署自己的相同域代理,该代理将检查上传站点是否存在该文件,然后将该响应返回给客户端。
父文档还需要知道上传文件的名称。由于相同的域策略,您可能无法确定文件名,这在使用代理检查文件是否存在时会带来挑战。你怎么知道你在查什么?
发布于 2011-02-02 20:54:01
嗨,前几天我遇到了一篇文章,当时我想找一种方法在iFrames和通过名称加载它们的窗口之间来回交谈。
http://softwareas.com/cross-domain-communication-with-iframes
演示- http://ajaxify.com/run/crossframe/duo/
// site 1 code
<iframe name="frame1" src="site2">因此,假设您的第一个站点加载到您的第二个站点,上面的iFrame。第二个站点代码应该将此代码添加到其中。
//site 2 code
$(something).load('url', function() {
parent.frames["frame1"].css('border', '1px green solid');
});我相信您也可以从站点1向iFrame发出函数调用:
//site 1 code
parent.frames["frame1"].functionName(variables);发布于 2011-02-06 14:07:56
服务器端代理
apache配置
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_http_module modules/mod_proxy_http.so
ProxyRequests Off
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
ProxyPass /foo http://mywebsite.com/
ProxyPassReverse /foo http://mywebsite.com/ 我希望这能帮到你
因此,如果您从www.bar.com向www.bar.com/foo创建请求,apache将传递给www.mywebsite.com。
https://stackoverflow.com/questions/4875646
复制相似问题