微信打开域名跳转浏览器纯PHP代码已适配安卓和IOS系统

  • 内容
  • 相关
 已经做了安卓和IOS的适配。需要替换其中要跳转的网址,然后保存为php文件,在微信内访问即可实现自动跳转!

<?php
error_reporting(0);
if($_GET['open']==1 && strpos($_SERVER['HTTP_USER_AGENT'], 'MicroMessenger')!==false){
header("Content-Disposition: attachment; filename=\"load.doc\"");
header("Content-Type: application/vnd.ms-word;charset=utf-8");
}
?>
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>Welcome</title>
    <meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" name="viewport"/>
    <meta content="yes" name="apple-mobile-web-app-capable"/>
    <meta content="black" name="apple-mobile-web-app-status-bar-style"/>
    <meta name="format-detection" content="telephone=no"/>
    <meta content="false" name="twcClient" id="twcClient"/>
    <style>
body,html{width:100%;height:100%}
*{margin:0;padding:0}
body{background-color:#fff}
.top-bar-guidance{font-size:15px;color:#fff;height:40%;line-height:1.8;padding-left:20px;padding-top:20px;background:url(//gw.alicdn.com/tfs/TB1eSZaNFXXXXb.XXXXXXXXXXXX-750-234.png) center top/contain no-repeat}
.top-bar-guidance .icon-safari{width:25px;height:25px;vertical-align:middle;margin:0 .2em}
.app-download-btn{display:block;width:214px;height:40px;line-height:40px;margin:18px auto 0 auto;text-align:center;font-size:18px;color:#2466f4;border-radius:20px;border:.5px #2466f4 solid;text-decoration:none}
    </style>
</head>
<body>
<div class="top-bar-guidance">
    <p>点击右上角<img src="//gw.alicdn.com/tfs/TB1xwiUNpXXXXaIXXXXXXXXXXXX-55-55.png" class="icon-safari" /> Safari打开</p>
    <p>可以继续访问本站哦~</p>
</div>
<a class="app-download-btn" id="BtnClick" href="javascript:;">
    点此继续访问
</a>
<script>

var url = 'http://pjax.cc/'; //填写要跳转到的网址

document.querySelector('body').addEventListener('touchmove', function (event) {
	event.preventDefault();
});
window.mobileUtil = (function(win, doc) {
	var UA = navigator.userAgent,
		isAndroid = /android|adr/gi.test(UA),
		isIOS = /iphone|ipod|ipad/gi.test(UA) && !isAndroid,
		isBlackBerry = /BlackBerry/i.test(UA),
		isWindowPhone = /IEMobile/i.test(UA),
		isMobile = isAndroid || isIOS || isBlackBerry || isWindowPhone;
	return {
		isAndroid: isAndroid,
		isIOS: isIOS,
		isMobile: isMobile,
		isWeixin: /MicroMessenger/gi.test(UA),
		isQQ: /QQ/gi.test(UA)
	};
})(window, document);

if(mobileUtil.isWeixin){
	if(mobileUtil.isIOS){
		url = "https://t.asczwa.com/taobao?backurl=" + encodeURIComponent(url);
		document.getElementById('BtnClick').href=url;
	}else if(mobileUtil.isAndroid){
		url = '?open=1';
		document.getElementById('BtnClick').href=url;
		var iframe = document.createElement("iframe");
		iframe.style.display = "none";
		iframe.src = url;
		document.body.appendChild(iframe);
	}
}else{
	document.getElementById('BtnClick').href=url;
	window.location.replace(url);
}
//setTimeout('WeixinJSBridge.invoke("closeWindow", {}, function(e) {})', 2000);
</script>
</body>
</html>


本文标签:

版权声明:若无特殊注明,本文皆为《Leek》原创,转载请保留文章出处。

本文链接:微信打开域名跳转浏览器纯PHP代码已适配安卓和IOS系统 - https://pjax.cc/46.html

发表评论

电子邮件地址不会被公开。 必填项已用*标注

未显示?请点击刷新

允许邮件通知

评论

4条评论
  1. avatar

    日后再说 Lv.1 Chrome 65.0.3325.181 Chrome 65.0.3325.181 Windows Windows 回复

    表情 写得好好哟,我要给你生猴子!

    河北省保定市 电信

    1. avatar

      日后再说 Lv.1 Chrome 65.0.3325.181 Chrome 65.0.3325.181 Windows Windows 回复

      滴!学生卡!打卡时间:上午10:13:01,请上车的乘客系好安全带~

      河北省保定市 电信

      1. avatar

        浪子妄言 Chrome 65.0.3325.181 Chrome 65.0.3325.181 Windows Windows 回复

        12

        河北省保定市 电信

        1. avatar

          久伴 Lv.1 Chrome 64.0.3282.186 Chrome 64.0.3282.186 Windows 7 x64 Edition Windows 7 x64 Edition 回复

          学习了,大佬,大佬我是你小弟,日后多多关照 表情

          湖北省武汉市 电信