Javascript编程 :编一个小程序 如何让它自动打开一个网页,然后间隔10秒再自动关闭这个网页。如此循环。

Javascript编程 :编一个小程序 如何让它自动打开一个网页,然后间隔10秒再自动关闭这个网页。如此循环。,第1张

var _iframe

function gostart(){

openPage()

setTimeout(function(){closePage()},2000)

}

function openPage(){

_iframe = document.createElement("iframe")

_iframe.src="http://www.baidu.com"

document.body.appendChild(_iframe)

}

function closePage(){

document.body.removeChild(_iframe)

}

自己通过setTimeout函数来控制循环,不懂setTimeout的话,去百度上搜索一下用法。

给分吧。^_^

多次拒绝登录和允许登录

微信小程序的登录获取用户信息,是通过微信d出窗口,用户可点击允许 和拒绝两个按钮,点击允许,则获取用户信息登录成功,若点击拒绝,则获取失败,可通过二次请求调用d起获取用户信息窗口。

具体代码如下:

//app.js

App({

onLaunch: function () {

//调用API从本地缓存中获取数据

var logs = wx.getStorageSync('logs') || []

logs.unshift(Date.now())

wx.setStorageSync('logs', logs)

console.log('logs',logs)

},

getUserInfo:function(cb){

var that = this

//调用登录接口

function getOpenid(backMsg){

that.globalData.userInfo = backMsg.userInfo

that.globalData.encryptedData = backMsg.encryptedData

that.globalData.iv = backMsg.iv

that.globalData.login = true

console.log(that.globalData.code)

wx.request({

url:that.localUrl+'Login/sendCodeLogin',

data:{

code:that.globalData.code,

encryptedData: backMsg.encryptedData,

iv:backMsg.iv

},

success:function(openData){

console.log('返回openid',openData,openData.data)

if(openData.data.code==1001){

that.globalData.openid = openData.data.data.openid

wx.setStorageSync('openid',that.globalData.openid)

wx.setStorageSync('userInfo',that.globalData.userInfo)

wx.setStorageSync('isManager', openData.data.data.isManager)

wx.showToast({

title: '登录成功',

icon: 'success',

duration: 500

})

typeof cb == "function" &&cb(that.globalData.userInfo)

}else{

wx.showLoading({

title: '登录失败'

})

setTimeout(function () {

wx.hideLoading()

}, 500)

}

}

})

}

wx.login({

success: function (msg) {

console.log('code',msg)

if(msg.code){

that.globalData.code = msg.code

if(that.globalData.login==false){

wx.openSetting({

success: function (data) {

if(data) {

if (data.authSetting["scope.userInfo"] == true) {

//loginStatus = true

wx.getUserInfo({

withCredentials: false,

success: function (res) {

console.log('第二次成功',res)

getOpenid(res)

},

fail: function (res) {

that.globalData.login = false

console.log('二次失败',res)

}

})

}else{

that.globalData.login = false

console.log('二次失败02')

}

}

},

fail: function () {

console.info("设置失败返回数据")

}

})

}else{

wx.getUserInfo({

success: function (res) {

console.log('第一次成功',res)

getOpenid(res)

},fail:function(msg){

that.globalData.login = false

console.log('第一次失败',msg)

}

})

}

}

},

fail:function(res){

console.log(res)

}

})

},

globalData:{

userInfo:null,

encryptedData:null,

iv:null,

openid:null,

code:null

}

})


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/yw/8079762.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-13
下一篇 2023-04-13

发表评论

登录后才能评论

评论列表(0条)

保存