Getting flash src after redirecting 302 OR element inside embed / object / iframe (cross-domain) tag

URL example.com/redir automatically redirects the user (HTTP 302) to example.com/ hi.SWF ? Message = Message + Value.

How can I get the message value using javascript or flash in the following example?

<!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> 

Please note that:

  • The above .html is hosted at cross-domain.com , like any other file involved in the solution ( .swf .js , .html , .css , etc.),
  • You have no control over example.com ;
  • You have no control over hi.SWF ;
  • You can change the <embed> tag to <object> or <IFrame> ;
+6
source share
2 answers

Simple answer:

You cannot do this because of policies of the same origin.
User cookies will not be sent to your request.

0
source

I think the easiest way to get the URL of your redirected swf and its parameters is to use another swf as the loader for your current one, where you can get the URL and parameters passed to your redirected swf, and then you can send it to JavaScript via ExternalInterface

To do this, take a look at this example:

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 side:

In this example, suppose we have a .htaccess file, for example:

.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> 

What all!

If you want to know more about how to use ExternalInterface , you can look here .

Hope this helps.

0
source

All Articles