Get URL of the Page Where SWF is Embedded


/ Published in: ActionScript 3
Save to your folder(s)

<p>To get the complete URL as it appears in your web browser's address bar we use AS3's <a href="http://help.adobe.com/en_US/FlashPlatform//reference/actionscript/3/flash/external/ExternalInterface.html">ExternalInterface</a> class. Without going into too much detail, know that in this example we use ExternalInterface to access the DOM (Document Object Model) of the HTML page which contains our Flash. A downside of ExternalInterface is that the SWF must be embedded in the HTML page with the "allowscriptaccess" parameter set to either "sameDomain" or "always". This is OK when you control the embedding of a SWF but unfortunately cannot be relied upon if the SWF may be run on third party websites. Don’t forget to add import flash.external.ExternalInterface at the top of your document.</p>


Copy this code and paste it in your HTML
  1. function get currentURL():String
  2. {
  3. var url:String;
  4. if (ExternalInterface.available) {
  5. return ExternalInterface.call("window.location.href");
  6. }
  7. return url;
  8. }

URL: http://enva.to/e4ig6z

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.