点击链接弹出qq对话框

文章目录

  • 一、判断浏览器是移动端还是pc端
  • 二、点击链接实现跳转
    • 1.pc端
    • 2.移动端
    • 2.示例


一、判断浏览器是移动端还是pc端

这里提供一种方法:利用js中的navigator对象。

var userAgent = navigator.userAgent;
     //console.log(userAgent);
     if(window.navigator.userAgent.match(/(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone)/i)) {
     
     //移动端
     console.log('mobile');
     } else {
     
     //pc端
     console.log('pc');
     }

二、点击链接实现跳转

1.pc端

1. tencent://Message/?Uin=你自己的qq号&websiteName=q-zone.qq.com&Menu=yes

<a href="tencent://Message/?Uin=你自己的qq号&websiteName=q-zone.qq.com&Menu=yes">联系客服</a>

2. http://wpa.qq.com/msgrd?v=3&uin=你自己家的qq号&Site=站点名字&Menu=yes

<a href="http://wpa.qq.com/msgrd?v=3&uin=你自己家的qq号&Site=站点名字&Menu=yes">联系客服</a>

2.移动端

mqqwpa://im/chat?chat_type=wpa&uin=你自己的qq号&version=1&src_type=web&web_src=oicqzone.com
安卓、苹果均适用。

<a href="mqqwpa://im/chat?chat_type=wpa&uin=你自己的qq号&version=1&src_type=web&web_src=oicqzone.com">联系客服</a>

2.示例

//
<a href="" id="service">联系客服</a>
//js
 var service = document.getElementById("service");
     var userAgent = navigator.userAgent;
     //console.log(userAgent);
     if(window.navigator.userAgent.match(/(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone)/i)) {
     
     //移动端
      service.href = "mqqwpa://im/chat?chat_type=wpa&uin=1111111111&version=1&src_type=web&web_src=oicqzone.com";
     } else {
     
     //pc端
     service.href = "tencent://Message/?Uin=1111111111&websiteName=q-zone.qq.com&Menu=yes";
     }

参考:https://blog.csdn.net/weixin_42703239/article/details/81638325?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522161097805016780262592784%2522%252C%2522scm%2522%253A%252220140713.130102334.pc%255Fblog.%2522%257D&request_id=161097805016780262592784&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2blogfirst_rank_v1~rank_blog_v1-1-81638325.pc_v1_rank_blog_v1&utm_term=qq&spm=1018.2226.3001.4450

你可能感兴趣的:(javascript)