微信应用页面分享地址的统一修改

微信应用右上角的“发送给朋友”“分享到朋友圈”“复制连接”等功能,能够把当前页面地址分享出去;咱们能够经过微信官方的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);
相关文章
相关标签/搜索