Url Class
操作url 使用示例:
require(['url'], function(Url){
var websiteUrl = 'http://modulex.github.io/5.0/api/classes/Path.html?test=iamtestcontent&date=2014.09.10#method_resolve';
var urlDataObj = Url.parse(websiteUrl);
// 得到的urlDataObj如下:
// {
// auth: undefined
// hash: "#method_resolve"
// host: "modulex.github.io"
// hostname: "modulex.github.io"
// href: "http://modulex.github.io/5.0/api/classes/Path.html?test=iamtestcontent&date=2014.09.10#method_resolve"
// path: "/5.0/api/classes/Path.html?test=iamtestcontent&date=2014.09.10"
// pathname: "/5.0/api/classes/Path.html"
// port: undefined
// protocol: "http:"
// query: "test=iamtestcontent&date=2014.09.10"
// search: "?test=iamtestcontent&date=2014.09.10"
// slashes: true
// }
urlDataObj.search = undefined;
urlDataObj.query = {
name : 'weekeight',
love : 'kissy'
};
var newUrl = Url.format(urlDataObj); //得到的newUrl是 http://modulex.github.io/5.0/api/classes/Path.html?name=weekeight&love=kissy#method_resolve
})
Methods
format
(
-
url
-
serializeArray
将url对象转为url字符串
Parameters:
Example:
require(['url'], function(Url){
var websiteUrl = 'http://modulex.github.io/5.0/api/classes/Path.html?test=iamtestcontent&date=2014.09.10#method_resolve';
var urlDataObj = Url.parse(websiteUrl);
urlDataObj.search = undefined;
urlDataObj.query = {
name : 'weekeight',
love : 'kissy',
arr : [1,2,3]
};
var newUrl = Url.format(urlDataObj); //得到的newUrl是 http://modulex.github.io/5.0/api/classes/Path.html?name=weekeight&love=kissy&arr%5B%5D=1&arr%5B%5D=2&arr%5B%5D=3#method_resolve
})
parse
(
-
url
-
parseQueryString
解析url字符串为url对象。url对象包括键值:auth,hash,host,hostname,href,path,pathname,port,protocol,query,search,slashes
resolve
()
得到绝对地址的url,算法逻辑参考nodeJs
Example:
require(['url'],function(Url){
Url.resolve('modulex.github.io/guides/','overlay/index.html'); //modulex.github.io/guides/overlay/index.html
})