Set Value from URL [JavaScript]

set nilai dari address bar dengan menggunakan JavaScript :
Code :
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<body>
<h1>JavaScript to Set Value from URL</h1>
<table border="1">
<tbody>
<tr><td>Nilai Page:</td><td><input id="page" type="text" value="" /></td></tr>
</tbody>
</table>
<script type="text/javascript">
$(window).bind("load", function() {
function getUrlQueryString(param) {
var outObj = {};
var qs = window.location.search;
if (qs != "") {
qs = decodeURIComponent(qs.replace(/\?/, ""));
var paramsArray = qs.split("&");
var length = paramsArray.length;
for (var i=0; i<length; ++i) {
var pageValArray = paramsArray[i].split("=");
pageValArray[0] = pageValArray[0].toLowerCase();
if (outObj[pageValArray[0]]) {
outObj[pageValArray[0]] = outObj[pageValArray[0]] + ";" + pageValArray[1];
} else {
if (pageValArray.length > 1) {
outObj[pageValArray[0]] = pageValArray[1];
} else {
outObj[pageValArray[0]] = true;
}
}
}
}
var retVal = param ? outObj[param.toLowerCase()] : qs;
return retVal ? retVal : ""
}
var page = getUrlQueryString("page");
$('#page').val(page);
});
</script>


Berikan Komentar yang bermanfaat dan sehat.

Posting Komentar (0)
Lebih baru Lebih lama