JS获取页面超链接传来的参数

    xiaoxiao2025-09-08  576

    <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>
    转载请注明原文地址: https://ju.6miu.com/read-1302453.html
    最新回复(0)