url 주소에서 매개변수 값 잘라내기
(GET방식 매개변수 값 받아오기)
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
<script type="text/javascript">
function fn_load() {
var str = returnUrlParams();
alert(str);
}
function returnUrlParams() {
var array = [], hash;
//직접가져오기
//var url = "http://goddfs?idx=233&name=goddfs";
//var url_Address = url.slice(url.indexOf('?') + 1).split('&');
//URL 에서 가져오기
var url_Address = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
for (var i = 0; i < url_Address.length; i++) {
hash = url_Address[i].split('=');
array.push(hash[1]);
//console.log(hash);
array[hash[0]] = hash[1];
}
return array;
}
</script>
</head>
<body>
<form id="form1" runat="server" >
<div>
<input type="button" id="btnOK" onclick="fn_load();" value="버튼" />
<input type="text" id="txt" />
</div>
</form>
</body>
</html>
결과화면입니다.
끝~