获取域名在AS3域名

2023-09-08 12:52:22 作者:我承包了所有鱼塘i

我知道如何让页面的URL,但我怎么能简单地提取域和单独的域名?

I know how to get the URL of the page, but how can I extract simply the domain and the domain alone?

必须返回相同的值带或不带WWW,而且还必须考虑返回文件的相同值,有或没有斜线等。

It must return the same value with or without www, and it must also return the same value regardless of file, with or without trailing slash, etc.

所以 www.domain.com 将返回 domain.com 站点。 COM /的index.php 将返回相同的为好。

So www.domain.com would return domain.com, and domain.com/index.php would return the same as well.

这可能吗?

如果是这样,是有办法做到这一点,而无需调用 ExternalInterface.call('window.location.href.toString')

If so, is there a way to do it without calling ExternalInterface.call('window.location.href.toString')?

感谢您的帮助!

推荐答案

您可以使用LoaderInfo类,然后修剪下来一个普通的前pression。

You can use the loaderInfo class, and then trim it down with a regular expression.

喜欢这一点。此跟踪发现[0]会向下返回域到.COM。

Like this. This trace of found[0] will return the domain down to the .com.

package{

import flash.display.LoaderInfo
import flash.display.MovieClip


public class sample extends MovieClip {
    public var urlStr:String;

    public function sample (){
        getLocation(this.loaderInfo.url);

    }
    public function getLocation(urlStr:String){
        var urlPattern:RegExp = new RegExp("http://(www|).*?\.(com|org|net)","i");
        var found:Object =  urlPattern.exec(urlStr);
            trace(found[0]);

    }

}

}