Javascript 在302重定向或嵌入/object/iframe标记内的元素后获取flash src(跨域)
URL example.com/redir将自动将用户(HTTP 302)重定向到example.com/hi.SWF?message=message+Value 在下面的示例中,如何使用javascript或flash获取消息值Javascript 在302重定向或嵌入/object/iframe标记内的元素后获取flash src(跨域),javascript,html,flash,embed,element,Javascript,Html,Flash,Embed,Element,URL example.com/redir将自动将用户(HTTP 302)重定向到example.com/hi.SWF?message=message+Value 在下面的示例中,如何使用javascript或flash获取消息值 <!DOCTYPE html> <html> <body> <embed id="foo" src="https://example.com/redir"></embed>
<!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>
考虑一下:我认为获取重定向swf的url及其参数的最简单方法是使用另一个swf作为当前swf的加载程序,在这里,您可以获取传递给重定向swf的url和参数,然后通过JavaScript将其发送到JavaScript 为此,请看以下示例: 动作脚本:
// 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);
}
Redirect /redirect /new.swf?message=a%20message%20here
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
}
<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>
HTML端:
// 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);
}
Redirect /redirect /new.swf?message=a%20message%20here
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
}
<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>
对于本例,假设我们有一个.htaccess
文件,如下所示:
.htaccess:
// 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);
}
Redirect /redirect /new.swf?message=a%20message%20here
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
}
<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>
JavaScript:
// 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);
}
Redirect /redirect /new.swf?message=a%20message%20here
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
}
<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>
HTML:
// 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);
}
Redirect /redirect /new.swf?message=a%20message%20here
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
}
<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
的更多详细信息,可以查看
希望能有所帮助。简单回答:
你不能那样做,因为同一原产地的政策。
您的请求中不会包含用户的cookies。此处是否包含Flash SWF文件?如果没有,那么你不能用Flash做任何事情。@SunilD。对不起,我编辑了这个问题。现在flash的东西是有意义的。我相信现在问题更清楚了。除非我忘记了什么,否则你不能忘记,因为那样会违反相同的域规则。