Scripts 学盟
标题: javascript 相对路径转绝对路径 [打印本页]
作者: 混混@普宁.中国 时间: 2017-4-1 19:26:44 标题: javascript 相对路径转绝对路径
var resolve = function() {
var iframe = document.createElement('iframe');
iframe.style.cssText = 'position:absolute; left:-1000px; top:-1000px;';
document.body.appendChild(iframe);
return function(path1, path2) {
iframe.contentWindow.document.write("<html><head><base href='"+path1+"'/></head><body><a href='"+path2+"'>a</a></body></html>");
return iframe.contentWindow.document.body.firstChild.href;
};
}();
resolve('http://www.linjunhai.com/blog/article.asp?id=183', '../a/b/c.html');
// http://www.linjunhai.com/a/b/c.html
欢迎光临 Scripts 学盟 (http://www.iscripts.org/) |
Powered by Discuz! X2 |