Get URL of current page from Flex 3?

前端 未结 7 794
死守一世寂寞
死守一世寂寞 2021-01-12 17:58

How do I determine the URL of the current page from within Flex?

相关标签:
7条回答
  • 2021-01-12 17:58

    I tried the e:BrowserChangeEvent version and inside my class it didnt or wasnt the appropriate moment for this event to work so in short it didn't work !

    Using Application.application.loaderInfo.loaderURL is my preferred solution.

    0 讨论(0)
  • 2021-01-12 18:05

    I searched and came up with this url. I've honestly never used Flex, but it looks like the important part of that document is this:

    private function showURLDetails(e:BrowserChangeEvent):void {
      var url:String = browserManager.url;
      baseURL = browserManager.base;
      fragment = browserManager.fragment;                
      previousURL = e.lastURL;                
    
      fullURL = mx.utils.URLUtil.getFullURL(url, url);
      port = mx.utils.URLUtil.getPort(url);
      protocol = mx.utils.URLUtil.getProtocol(url);
      serverName = mx.utils.URLUtil.getServerName(url);
      isSecure = mx.utils.URLUtil.isHttpsURL(url);        
    }
    

    Either way, good luck! :)

    0 讨论(0)
  • 2021-01-12 18:07

    From the Application:

    var myUrl:String = Application.application.url;
    
    0 讨论(0)
  • 2021-01-12 18:12

    From the Application, use: this.loaderInfo.loaderURL

    to break it apart and use parts of it do:

    var splitURL:Array = this.loaderInfo.loaderURL.split('/');
    var baseURL:String = "http://"+splitURL[2];
    
    0 讨论(0)
  • 2021-01-12 18:13

    Let's be clear here.

    1. If you want the URL of the loaded SWF file, then use one of these.

    Inside your application:

    this.url;
    

    From anywhere else:

    Application.application.url; // Flex 3
    FlexGlobals.topLevelApplication.url; // Flex 4
    

    If you are loading your SWF inside another SWF, then keep in mind that the code above will give different values. this.url will return the url of your SWF, where as Application.application.url will give the url of the parent/root SWF.

    2. If you want to know the URL that is in the browser address bar, then use one of these.

    BrowserManager method(Make sure you have the History.js included in your wrapper html for this to work):

    var browser:IBrowserManager = BrowserManager.getInstance(); 
    browser.init();
    var browserUrl:String = browser.url; // full url in the browser
    var baseUrl:String = browser.base; // the portion of the url before the "#"
    var fragment:String = browser.fragment; // the portion of the url after the "#"
    

    JavaScript method:

    var browserUrl:String = ExternalInterface.call("eval", "window.location.href");
    

    If you are parsing the url for parameters, don't forget about this useful function:

    // parses a query string like "key=value&another=true" into an object
    var params:Object = URLUtil.stringToObject(browserURL, "&");
    
    0 讨论(0)
  • 2021-01-12 18:14
    ExternalInterface.call("window.location.href.toString");
    
    0 讨论(0)
提交回复
热议问题