获取js连接参数js_args

时间:2022-12-07 03:26:23

获取js连接参数,如下以链接:

<script src="js/jscript.js?skin=green" type="text/javascript"></script>

console.log(_getArgs('skin'));  //结果:green


/*!
* _path 获取组件核心文件lhgdialog.js所在的绝对路径
* _args 获取lhgdialog.js文件后的url参数组,如:lhgdialog.js?self=true&skin=aero中的?后面的内容
*/
var _args, _path = (function (script, i, me) {
var l = script.length; for (; i < l; i++) {
me = !!document.querySelector ?
script[i].src : script[i].getAttribute('src', 4); if (me.substr(me.lastIndexOf('/')).indexOf('jscript') !== -1)
break;
} me = me.split('?'); _args = me[1]; return me[0].substr(0, me[0].lastIndexOf('/') + 1);
})(document.getElementsByTagName('script'), 0);
/*!
* 获取url参数值函数
* @param {String}
* @return {String||null}
* @demo lhgdialog.js?skin=aero | _getArgs('skin') => 'aero'
*/
var _getArgs = function (name) {
if (_args) {
var p = _args.split('&'), i = 0, l = p.length, a;
for (; i < l; i++) {
a = p[i].split('=');
if (name === a[0]) return a[1];
}
}
return null;
}
/*! 取皮肤样式名,默认为 default */
var _skin = _getArgs('skin') || 'default'; /*_____________测试________________*/
console.log(_getArgs('skin')); //结果:green /*! 开启IE6 CSS背景图片缓存 */
try {
_doc.execCommand('BackgroundImageCache', false, true);
} catch (e) { };