JS获取地址栏并拼接參数
比方地址栏是这种:http://www.aa.com/detail.aspx?code=1&start=2014-12-01&end=2014-12-23&name=abc
要获取到“?
code=1&start=2014-12-01&end=2014-12-23&name=abc”,例如以下:
前台页面head标签内:
<script type="text/javascript"> function GetQueryString(name) { var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); var r = window.location.search.substr(1).match(reg); if (r != null) return unescape(r[2]); return null; } function GetUrlQueryString() { var query = '?'; var code = escape(GetQueryString("code")); if (code != null && code.toString().length > 0) { query += 'code=' + code + '&'; } var start = escape(GetQueryString("start")); if (start != null && start.toString().length > 0) { query += 'start=' + start + '&'; } var end = escape(GetQueryString("end")); if (end != null && end.toString().length > 0) { query += 'end=' + end + '&'; } var name = escape(GetQueryString("name")); if (name != null && name.toString().length > 0) { query += 'name=' + name; } return query; } </script>
button:
<input type="button" value="导出" class="button1" onclick="javascript:window.open('ExportToExcel.aspx' + GetUrlQueryString());" />