获取域名在AS3 [英] Getting domain in AS3

查看:109
本文介绍了获取域名在AS3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道如何让页面的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]);

    }

}

}

这篇关于获取域名在AS3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆