bobpoekert
bobpoekert

Reputation: 1014

How do I get the domain of the page that's loading my swf when I don't have script access?

I need my swf to be able to see the domain of the page that it's loaded on. Normally to to this I would just look at window.location over ExternalInterface, but in this particular case the swf is going to be embedded with allowscriptaccess="never", so that's not going to work. Is there an actual api that will give me that or do I have to resort to ugly hacks?

Upvotes: 2

Views: 1413

Answers (4)

kontur
kontur

Reputation: 5220

Actionscript 3 actually has a property you can query straight, in flash.system.Security(http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/system/Security.html#pageDomain), like so:

import flash.system.Security;
...
var domain:String = Security.pageDomain;

It will give you "[t]he domain portion of the HTML page containing the swf."

Upvotes: 2

bobpoekert
bobpoekert

Reputation: 1014

It turns out that there's no direct way to do this. However, you can do the following:

  1. Have the path to the swf go to a script on your server
  2. Have that script read the referer [sic] header and 302 to the static file server where the swf file is, putting the value of the referer in a get variable
  3. Parse the url (gotten from loaderInfo.url), and extract the variable you added.

In order to prevent this value from being forged (by people linking directly to the static file server, skipping the redirect) you have to have your static file server verify that the value of the get variable is the same as the value in the referer header before serving the file (which I know you can do in nginx).

Upvotes: 0

www0z0k
www0z0k

Reputation: 4434

loaderInfo.loaderURL

Upvotes: 0

cmann
cmann

Reputation: 1980

Have you tried this :

var pageURL:String = stage.loaderInfo.url;

Upvotes: 0

Related Questions