=== 호출 ===
<script type="text/javascript" src="http://abc/js/custom.js?from=mycall&type=222"></script>
=== 스크립트 ===
var scripts = document.getElementsByTagName('script');
var myScript = scripts[ scripts.length - 1 ];
var queryString = myScript.src.replace(/^[^\?]+\??/,'');
var params = parseQuery( queryString );
alert(params['from']);
alert(params['type']);
function parseQuery ( query ) {
var Params = new Object ();
if ( ! query ) return Params; // return empty object
var Pairs = query.split(/[;&]/);
for ( var i = 0; i < Pairs.length; i++ ) {
var KeyVal = Pairs[i].split('=');
if ( ! KeyVal || KeyVal.length != 2 ) continue;
var key = unescape( KeyVal[0] );
var val = unescape( KeyVal[1] );
val = val.replace(/\+/g, ' ');
Params[key] = val;
}
return Params;
}
'IT > Javascript' 카테고리의 다른 글
[bootstrap datepicker] 한글 버전 (0) | 2017.07.03 |
---|---|
[javascript] json 이쁘게 보여주는법 (0) | 2017.05.11 |
[javascript, jquery] for, foreach (0) | 2017.04.24 |
URLEncode Refference (0) | 2015.04.02 |
Google Maps JavaScript API v3 (0) | 2014.08.06 |