安卓微信浏览器js打开文件

JavaScript08

安卓微信浏览器js打开文件,第1张

android安卓手机微信浏览器偶尔也有这样的问题,经过多次调试,发现是微信浏览器缓存了渲染页面,没有重新渲染页面,导致window.onload中JS无法执行。

经过以上分析判断,给出的解决方案就是,如果使用了缓存,自动重载页面。以下是JS代码解决方案:

window.onpageshow = function(event) {

if (event.persisted) {

window.location.reload()

}

}

或者下方代码:

var isPageHide = false

window.addEventListener('pageshow', function () {

if (isPageHide) {

window.location.reload()

}

})

window.addEventListener('pagehide', function () {

isPageHide = true

})

html头部处理缓存信息:

扩展说明:

pageshow:

当一条会话历史记录被执行的时候将会触发页面显示(pageshow)事件。(这包括了后退/前进按钮操作,同时也会在onload 事件触发后初始化页面时触发)

微信小程序实例index.js代码如下:可以搜索小程序名称: 快递最后一公里实例index.js代码var app = getApp()Page({/*** 页面的初始数据*/data: { //三张图片轮播imgUrls: [{imageUrl: '/images/weicha/timg1.jpg',},{imageUrl: '/images/weicha/timg2.jpg',},{imageUrl: '/images/weicha/timg3.jpg',}],indicatorDots: false,autoplay: false,interval: 5000,duration: 800,},onSwiperTab: function (e) {/*var postId = e.target.dataset.postIdwx.navigateTo({url: postId,})*/}, /*** 生命周期函数--监听页面加载*/onLoad: function (options) {app.loginWinCha(this.initPageData)},//初始化登录才能查看的数据initPageData: function () {this.setData({componentList: [{id: 1,url: '../weicha/express/courier/index',imageUrl: '/images/weicha/timg1_1.jpg',title: '快递小哥(送快递)',queryType: 'courier'},{id: 2,url: '../weicha/express/seller/index',imageUrl: '/images/weicha/timg1_2.jpg',title: '合作商家(代收快递)',queryType: 'seller'},{id: 3,url: '../weicha/express/personal/index',imageUrl: '/images/weicha/timg1_3.jpg',title: '收件人(签收快递)'},{id: 4,url: '../weicha/express/logistics/index',imageUrl: '/images/weicha/timg1_4.jpg',title: '快递物流查询'}]})},onItemClick: function (e) {var targetUrl = e.currentTarget.dataset.payvar targetQueryType = e.currentTarget.dataset.indexif (targetQueryType == "seller") {var reqData = {seller_openId: app.globalData.openid,status: '2'}this.queryDBUtil("sellerInfo", reqData, targetQueryType, targetUrl,"亲,您暂未申请商家,请提交商家申请!")} else if (targetQueryType == "courier") {var reqData = {courier_openId: app.globalData.openid,status: '2'}this.queryDBUtil("courierInfo", reqData, targetQueryType, targetUrl,"亲,您暂未申请快递员,请提交快递员申请!")} else {wx.navigateTo({url: targetUrl})}},queryDBUtil: function (reqCollectionName, reqData,queryType, retUrl,retMgs){wx.cloud.callFunction({name: "utilsDB",data: {collectionName: reqCollectionName,collectionWhere: reqData},complete: res =>{let retStatus = '1'if (res.result.data.length >= 1) {retStatus = res.result.data[0].status}if (retStatus == '2') {if (queryType == "seller"){app.globalData.seller = res.result.data[0]} else if (queryType == "courier"){app.globalData.courier = res.result.data[0]}wx.navigateTo({url: retUrl})} else {wx.showToast({icon: 'none',title: retMgs})}},fail: err =>{wx.showToast({icon: 'none',title: retMgs})}})}})

你好,调用微信js最简单的办法,就是在java代码调用微信的Android SDK(具体用法看微信开发品台的示例,很简单), 在js里使用jsb.reflection调用你的java方法。IOS也一样。