在302重定向或嵌入/对象/iframe标签中的元素后获得flash src(跨域)
Getting flash src after a 302 redirect OR an element inside an embed/object/iframe tag (cross-domain)
URL example.com/redir会自动将用户(HTTP 302)重定向到example.com/hi.SWF?message=消息+值。
如何获得消息值,使用javascript或flash,在下面的例子中?
<!DOCTYPE html>
<html>
<body>
<embed id="foo" src="https://example.com/redir"></embed>
<!-- Remember that example.com/redir will be automatically redirected to example.com/hi.SWF?message=Message+Value -->
<!-- The code to get the message value must go here -->
</body>
</html>
认为:
- 上述.html托管在cross-domain.com中,就像解决方案中涉及的任何其他文件一样(.swf, .js, .html, .css等);
- 您无法控制example.com;
- 您无法控制hi.SWF;
- 您可以将标签更改为或 & lt; iframe> ,
简单回答:
你不能那样做,因为同源策略。
用户的cookie将不会在您的请求中携带。
我认为获得重定向swf的url及其参数的最简单方法是使用另一个swf作为当前swf的加载器,在那里您可以获得url和参数传递给重定向swf,然后您可以通过ExternalInterface
将其发送到JavaScript。
看一下这个例子:
ActionScript:
// url : the url of the current swf
// this url is passed by flash vars in the html page
// default value : http://www.example.com/redirect
var swf_url:String = this.loaderInfo.parameters.url || 'http://www.example.com/redirect',
// fn : the name of the js function which will get the url and the message param
// this name is passed by flash vars in the html page
// default value : console.log
js_function:String = this.loaderInfo.parameters.fn || 'console.log',
message:String = 'no message';
var url_request:URLRequest = new URLRequest(swf_url);
var swf_loader:Loader = new Loader();
swf_loader.contentLoaderInfo.addEventListener(Event.COMPLETE, on_content_load);
swf_loader.load(url_request);
function on_content_load(e:Event): void
{
var loader_info:LoaderInfo = LoaderInfo(e.currentTarget);
// get the message param or use the default message
message = loader_info.parameters.message || message;
// if ExternalInterface is available, send data to js
if(ExternalInterface.available)
{
// send the swf url and the message param to the js function
ExternalInterface.call(js_function, { url: loader_info.url, message: message });
}
// show the redirected loaded swf
addChild(swf_loader);
}
HTML边:
在这个例子中,假设我们有一个.htaccess
文件,如下所示:
。htaccess:
Redirect /redirect /new.swf?message=a%20message%20here
JavaScript: function get_data_from_flash(data)
{
console.log('url : ' + data.url);
// gives :
// url : http://www.example.com/new.swf?message=a%20message%20here
console.log('message : ' + data.message);
// gives :
// message : a message here
}
HTML: <object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="550" height="400">
<param name="movie" value="loader.swf" />
<param name="flashvars" value="url=http://www.example.com/redirect&fn=get_data_from_flash" />
<object type="application/x-shockwave-flash" data="loader.swf" width="550" height="400">
<param name="flashvars" value="url=http://www.example.com/redirect&fn=get_data_from_flash" />
</object>
</object>
就这些!
如果你想了解更多关于如何使用ExternalInterface
的细节,你可以看看这里。
希望能有所帮助。
相关文章:
- CKEditor Widget-阻止编辑可编辑元素本身
- 如何设置html元素填充的动画
- 如何将HTML id分配给元素,以及如何将JavaScript应用于元素
- 使用 jQuery 的 .on 函数如何获取事件的原始元素
- 使用clickToggle并在单击另一个元素时关闭元素
- 单击时将焦点更改为元素
- 表追加而不附加最后一个元素
- 事件中的Flash元素
- 将 Javascript 单击回调分配给 Flash 元素
- 用flash元素在网页上截图
- 在Chrome扩展弹出窗口中保持Flash元素处于活动状态
- 是否可以在HTML元素上使用jQuery钩子来触发对flash元素的点击
- 我想把页面上的这个flash元素变成javascript/jquery.
- 在302重定向或嵌入/对象/iframe标签中的元素后获得flash src(跨域)
- ZeroClipboard:当浏览器中没有Flash时隐藏元素
- Flash元素内部的href
- 当Flash层放置在元素上时,保留CSS动画
- 用JQuery程序化地点击页面上的Flash元素
- Jquery/javascript flash函数用于多个元素
- 大量的Jquery和复选/单选/选择样式元素- Flash的无样式内容