H5页面底部前进、后退横栏怎么去除?

最近在写h5 的时候要求去掉页面的前进和后退的横栏,记录一下自己的解决方案。
在这里插入图片描述
1. 首先说明一下h5的流程

前端调起h5 授权 > 用code 从服务器换取token > 记录下token,之后的每次请求带上token

2. 发生问题的原因

每次h5授权的时候,微信会重定向,这时候我们的页面就会带上这个前进和后退的横栏。

3. 怎么解决
我的想法是如果重定向不发生在前端页面而是在后台会不会就可以了?

在我们进入真正的h5 页面之前加一个过渡页面来授权。
也就是说我们的项目入口是test/index.php 而实际上的h5 代码是在index.html 里。

  • 目录结构:
    在这里插入图片描述
  • 下面看一下代码:
    index.php
<?php 
if (!$_GET['code']){
	$url = 'https://open.weixin.qq.com/connect/oauth2/authorize?appid=appid&redirect_uri=http://***/test/index.php&response_type=code&scope=snsapi_base&state=1#wechat_redirect';
	die(header('location:'.$url));
}else{
	die(header('location:http://***/test/index.html?code='.$_GET['code']));
}

index.html

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=0">
	<meta http-equiv="X-UA-Compatible" content="ie=edge">
	<title>Document</title>
</head>
<body>
	这是我们的h5 页面
</body>
<script src="https://code.jquery.com/jquery-3.1.0.min.js"></script>
<script src="//cdn.bootcss.com/jquery-cookie/1.4.1/jquery.cookie.min.js"></script>
<script>
	function getQueryString(name) {
		var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
		var r = window.location.search.substr(1).match(reg);
		if(r != null) return decodeURI(r[2]);
		return null;
	}
</script>
</html>

也就是从index.php 进入后会带着code 被重定向到index.html。

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值