[前端]利用a标签获取url里所需的内容
2015-08-14 09:40
405 查看
function parseURL(url) { var a = document.createElement('a'); a.href = url; return { source: url, protocol: a.protocol.replace(':',''), host: a.hostname, port: a.port, query: a.search, params: (function(){ var ret = {}, seg = a.search.replace(/^?/,'').split('&'), len = seg.length, i = 0, s; for (;i<len;i++) { if (!seg[i]) { continue; } s = seg[i].split('='); ret[s[0]] = s[1]; } return ret; })(), file: (a.pathname.match(//([^/?#]+)$/i) || [,''])[1], hash: a.hash.replace('#',''), path: a.pathname.replace(/^([^/])/,'/$1'), relative: (a.href.match(/tps?://[^/]+(.+)/) || [,''])[1], segments: a.pathname.replace(/^//,'').split('/') }; }
获取file好像有错
来源:http://james.padolsey.com/javascript/parsing-urls-with-the-dom/
iframe里获取父页面的url
function getParentUrl() { var url = null; if (parent !== window) { try { url = parent.location.href; } catch (e) { url = document.referrer; } } return url; }
相关文章推荐
- AngularJS 教程
- CSS之盒子模型一
- js实现选中复选框文字变色的方法
- 如何学习3D Three.js 3D引擎
- jQuery length和size()的区别
- Jquery的运用
- js 表格合并
- Jquery的基本理念
- jsp页面foreach循环,表单提交,批量处理数据,
- JavaScript 属性介绍
- css position 定位
- avalon js实现仿微博拖动图片排序
- 并行编程(2) - sum.msic.Unsafe 二
- HTML 学习新理论
- 并行编程(1) - sum.msic.Unsafe 一
- javascript实现显示和隐藏div方法汇总
- javascript运算符及优先级
- jQuery照片伸缩效应,这不是一个简单的图像缩放,它不影响其它元素的布局
- 前端模块化开发的价值
- js-延迟处理函数