如何保持整个链接

时间:2019-07-03 01:48:12

标签: javascript url whatsapp messenger

我找到了这段代码,并且工作正常,从Messenger开启whatsapp发送预填充的消息。 问题是链接被削减=

Messenger的链接运行脚本: https://website.com/ShareonWhatsApp.html?text=Hi%20how%20are%20You!%20https://m.me/7673?ref=test--12345

缺少 = test--12345

<body>
<script type="text/javascript">
    function getQueryVariable(variable) {
        var query = window
            .location
            .search
            .substring(1);
        var vars = query.split("&");
        for (var i = 0; i < vars.length; i++) {
            var pair = vars[i].split("=");
            if (pair[0] == variable) {
                return pair[1];
            }
        }
        return(false);
    }
    function _isMobile() {
        var isMobile = (/iphone|ipod|android|ie|blackberry/i).test(navigator.userAgent.toLowerCase());
        return isMobile;
    }
    if (_isMobile()) {
        location.assign("whatsapp://send?text=" + getQueryVariable("text"))
    } else {
        location.assign("http://web.whatsapp.com/send?text=" + getQueryVariable("text"))
    }
</script>
Please close this window to get back to Messenger

2 个答案:

答案 0 :(得分:0)

您想在WhatsApp上发送消息吗?

//<![CDATA[
/* js/external.js */
var doc, bod, nav, M, I, mobile, WhatMessage; // for use on other loads
addEventListener('load', function(){
doc = document; bod = doc.body; nav = navigator;
M = function(tag){
  return doc.createElement(tag);
}
I = function(id){
  return doc.getElementById(id);
}
mobile = nav.userAgent.match(/Mobi/i);
WhatMessage = function(phone){
  this.phone = phone;
  this.link = function(message, linkText){
    var a = M('a');
    a.textContent = linkText || message;
    a.href = 'https://api.whatsapp.com/send?phone='+this.phone+'&text='+encodeURIComponent(message);
    return a;
  }
}
var wm = new WhatMessage('15551234567'), content = I('content');
content.appendChild(wm.link('See the Message'));
}); // load end
//]]>
/* css/external.css */
*{
  box-sizing:border-box; padding:0; margin:0;
}
html,body{
  width:100%; height:100%;
}
body{
  background:#ccc;
}
#content{
  padding:7px;
}
<!DOCTYPE html>
<html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en' lang='en'>
  <head>
    <meta charset='UTF-8' /><meta name='viewport' content='width=device-width, height=device-height, initial-scale:1' />
    <title>Test Template</title>
    <link type='text/css' rel='stylesheet' href='css/external.css' />
    <script type='text/javascript' src='js/external.js'></script>
  </head>
<body>
  <div id='content'>
  </div>
</body>
</html>

此功能不适用于此页面加载到该网站的iframe,因此请右键单击并在新标签页中打开,以查看其是否正常运行。应该可以在您的网站上工作。

答案 1 :(得分:0)