<script type="text/javascript">
var url = window.location.href;
function getUrlParam(url,name){
var pattern = new RegExp("[?&]" + name +"\=([^&]+)","g");
var matcher = pattern.exec(url);
var items = null;
if(matcher != null){
try{
items = decodeURIComponent(decodeURIComponent(matcher[1]));
}catch(e){
try{
items = decodeURIComponent(matcher[1]);
}catch(e){
items = matcher[1];
}
}
}
return items;
}
var imgUrl = getUrlParam(url,'id'); //此处id为url中真实参数名
if(imgUrl.indexOf(".pdf") >= 0 ){
window.location.href=imgUrl;
}else{
var content = "<img src='"+imgUrl+"' />"
$('div').append(content);
}
</script>
var url = window.location.href;
function getUrlParam(url,name){
var pattern = new RegExp("[?&]" + name +"\=([^&]+)","g");
var matcher = pattern.exec(url);
var items = null;
if(matcher != null){
try{
items = decodeURIComponent(decodeURIComponent(matcher[1]));
}catch(e){
try{
items = decodeURIComponent(matcher[1]);
}catch(e){
items = matcher[1];
}
}
}
return items;
}
var imgUrl = getUrlParam(url,'id'); //此处id为url中真实参数名
if(imgUrl.indexOf(".pdf") >= 0 ){
window.location.href=imgUrl;
}else{
var content = "<img src='"+imgUrl+"' />"
$('div').append(content);
}
</script>
本文介绍了一种通过JavaScript从当前页面URL中获取指定参数的方法,并根据获取到的参数动态调整页面内容。具体实现包括定义正则表达式匹配目标参数值、进行解码处理以及根据参数后缀判断是否直接跳转或展示图片。
3394

被折叠的 条评论
为什么被折叠?



