Get Current Browser URL - ActionScript 3

前端 未结 6 1622
悲&欢浪女
悲&欢浪女 2020-12-17 18:51

I\'m trying to get current browser url. I have already tried with External Call, and it didn\'t work. And with loaderInfo.url I receive the current SWF url.

相关标签:
6条回答
  • 2020-12-17 19:35

    There are a couple of ways to solve this problem, however all of them involve the use of JavaScript to query the browser directly.

    My preferred way to solve this problem would be to provide the URL via a flashVar property, direct from the embed code (personally, I would reccomend using SWFObject to make this easier); don't forget you will need to URL Encode it to avoid markup issues.

    var flashvars = {
      browserURL: escape(location.href)
    };
    swfobject.embedSWF("myContent.swf", "myContent", "300", "120", "9.0.0", "expressInstall.swf", flashvars);
    

    Now you will be able to access the Browser URL via the loaderInfo object:

    trace(stage.loaderInfo.parameters["browserURL"]);
    

    note that this will only work if you have control of generated HTML for your SWF file - if users are going to be grabbing the SWF and writing their own embed HTML, it's not going to work.

    If you don't have control of the flash embed HTML, then you will need to get flash to query the browser at runtime using the ExternalInterface class; other people have suggested the use of "window.location.href.toString" however this can prove problematic in IE6, I find the following works reliably across all browsers

    const browserURL : String = ExternalInterface.call("eval", "window.location.href");
    

    Note that in order for this to work, you will need to grant JavaScript access to your Flash movie, this is done, again, via the HTML embed code and the allowScriptAccess param

    0 讨论(0)
  • 2020-12-17 19:40
    var url:String = loaderInfo.loaderURL;
    

    seems to work too.

    0 讨论(0)
  • 2020-12-17 19:51

    I would try passing the required info in as a flashvar. Not the best out of the box solution I know, but it will work.

    Flash: FlashVars in AS3

    0 讨论(0)
  • 2020-12-17 19:52

    i think its posible to use the external interface an do it with javascript window.location

    0 讨论(0)
  • 2020-12-17 19:53

    Give this a go:

    import flash.external.ExternalInterface;
    
    var url:String = ExternalInterface.call("window.location.href.toString");
    if (url) textfield.text = url;
    

    should do the trick.

    0 讨论(0)
  • 2020-12-17 19:55

    I have been using flash for a long time and never noticed this one. It only gives the domain though for security. It does work through loaded swfs as well. Not sure about iframes.

    Security.pageDomain
    
    0 讨论(0)
提交回复
热议问题