JS獲取頁面超連結傳來的引數
阿新 • • 發佈:2019-02-08
<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>