微信應用右上角的「發送給朋友」「分享到朋友圈」「複製連接」等功能,能夠把當前頁面地址分享出去;咱們能夠經過微信官方的jsapi設置頁面的分享地址;這裏提供另外一種方案,咱們能夠在頁面的包含頁面中(個人是header.html),經過h5的pushState功能在前端設置,對後端影響很小。 html
function getUrlParam(name) { var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); var r = window.location.search.substr(1).match(reg); if (r != null) return unescape(r[2]); return null; } window.addEventListener('load', function() { var oid = getUrlParam('oid'); var url = window.location.href; if(oid == null){ oid = document.getElementById('cur_oid').value; if(url.indexOf('?')>0){ window.history.pushState({},0,url+'&oid='+oid); }else{ window.history.pushState({},0,url+'?oid='+oid); } } }, false);