解决方案有的摘录网络
1、微信网页 <video>标签 进入页面自动播放视频,且不全屏播放
开发模式下给video添加autoplay属性是可以进入页面直接播放视频,不清楚是不是移动端的原因!所以以下是移动端的解决方案
document.addEventListener("DOMContentLoaded", function() {
function audioAutoPlay() {
var video = document.getElementById("video");
video.play();
document.addEventListener(
"WeixinJSBridgeReady",
function() {
video.play();
},
false
);
}
audioAutoPlay();
});
// --创建触摸监听,当浏览器打开页面时,触摸屏幕触发事件,进行音频播放
document.addEventListener("touchstart", function() {
function audioAutoPlay() {
var video = document.getElementById("video");
video.play();
}
audioAutoPlay();
});
页面加载完毕和手机触摸屏幕都可以触发播放
微信浏览器 加了什么机制 为了给用户省流量,所以autoplay标签 失效了
2、关于微信openId
在开发环境 跟线上环境 配置 微信openId
openId机制,进入页面-页面跳转微信授权页面设置openId-回跳页面获取openId
//判断开发环境还是线上环境
if (document.domain.indexOf("192.168") >= 0) {
//http://map.simpleq.cn
window.serverUrl = "http://192.168.0.107:8058";
Util.setCookie("WzYkWechatOpenid", "oLP4Gj7HEc-twyZpemZ6gaVNlMII", "h12");
} else {
window.serverUrl = "";
}
//判断有没有openId
window.openid = "";
if (
typeof window.openid == "undefined" ||
window.openid == null ||
window.openid.length < 5
) {
var arrUrl = window.location.href.split("#");
var url = "";
url = arrUrl[1];
//没有openId 就去跳转微信授权页面
if (arrUrl.length >= 2) {
//获取对应 cookie 属性
var getcookie = Util.getCookie("WzYkWechatOpenid");
if (getcookie == null) {
window.location.href ="http://cswenyi.vhost4.cnvp.com.cn" + "/home/InitWx ";
}
//获取到openId
window.openid = getcookie;
}
}
下面是设置,获取,删除 openId
都是用vue写的,大佬复制粘贴 也能还要改改
//cookie 操作
getCookie: function(name) {
var arr,
reg = new RegExp("(^| )" + name + "=([^;]*)(;|$)");
if ((arr = document.cookie.match(reg))) {
console.log(arr);
//unescape 解码
return unescape(arr[2]);
} else {
return null;
}
},
delCookie: function(name) {
var exp = new Date();
exp.setTime(exp.getTime() - 1);
var cval = this.getCookie(name);
if (cval != null) {
document.cookie = name + "=" + cval + ";expires=" + exp.toGMTString();
}
},
setCookie: function(name, value, time) {
var strsec = this.getsec(time);
var exp = new Date();
exp.setTime(exp.getTime() + strsec * 1);
document.cookie =
name + "=" + escape(value) + ";expires=" + exp.toGMTString();
},
getsec:function(str)
{
var str1=str.substring(1,str.length)*1;
var str2=str.substring(0,1);
if (str2=="s")
{
return str1*1000;
}
else if (str2=="h")
{
return str1*60*60*1000;
}
else if (str2=="d")
{
return str1*24*60*60*1000;
}
}
3、暂时没有,有了会更新