gpt4 book ai didi

javascript - Iframe 上传者权限

转载 作者:太空宇宙 更新时间:2023-11-04 15:24:12 24 4
gpt4 key购买 nike

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

Permission denied for <http://www.mywebsite.com> to get property Window.document from <http://www.myotherwebsite.com>.

来到这一行:

$('iframe', top.document).css('border', '1px green solid'); 

上传完成后,我正在尝试使用边框设置 iframe 的样式。

我看到了其他问题,解决方案是制作一个服务器端代理,但我不知道如何制作一个代理让它工作并允许 jQuery 执行。

干杯。

增加了赏金。

最佳答案

服务器端代理可以帮助您克服这个问题。虽然浏览器只能使用同一域对其服务器进行 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;
?>

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

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

父文档还需要知道正在上传的文件的名称。由于相同的域策略,您可能无法确定文件名,这在使用代理检查文件是否存在时提出了挑战。你怎么知道你在检查什么?

关于javascript - Iframe 上传者权限,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4875646/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com