WhatsApp 仅使用 html 通过描述性文本共享 url 链接

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/45593013/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 14:50:26  来源:igfitidea点击:

WhatsApp use only html to share url link by a descriptive text

htmlsharehrefwhatsapp

提问by user6099216

I want to enable my website users to share the current web page url (stored in ViewBag.OgUrl) via WhatsApp.

我想让我的网站用户通过 WhatsApp 共享当前网页 url(存储在 ViewBag.OgUrl 中)。

The WhatsApp message should contain the url title(stored in ViewBag.OgTitle) which, when clicked, will open the url (stored in ViewBag.OgUrl).

WhatsApp 消息应包含url 标题(存储在 ViewBag.OgTitle 中),单击该标题将打开 url(存储在 ViewBag.OgUrl 中)。

This needs to be done by html without js.

这需要通过没有js的html来完成。

The standard way is:

标准方法是:

 @{
    var urlWhatsapp = "whatsapp://send?text=" + @ViewBag.OgUrl;
  }

And then simply:

然后简单地:

 <a href="@urlWhatsapp" target="_blank">WhatsApp Share</a>

This works fine apart from the fact that the actual url is shared and not the title.

除了共享实际 url 而不是标题这一事实之外,这很好用。

For example, a WhatsApp message contains the actual link http://example.org/while I would like it to show in WhatsApp:

例如,WhatsApp 消息包含实际链接http://example.org/,而我希望它显示在 WhatsApp 中:

First example

第一个例子

Edit: If one wants to get the title and the link just replace the code with:

编辑:如果想要获得标题和链接,只需将代码替换为:

  @{var urlWhatsapp = "whatsapp://send?text=" + @ViewBag.OgTitle + " - " + @ViewBag.OgUrl;}

<a class="fa fa-whatsapp" href="@urlWhatsapp" target="_blank"></a>

If one waits after the sharing, but before actually sending the message to the recipient, a clickable box appears above the original message (as would be for any whatsapp link with what is defined in the url - an image, text etc. according - see the example below) enter image description here

如果在共享之后等待,但在实际将消息发送给收件人之前,原始消息上方会出现一个可点击的框(对于任何带有 url 中定义的内容的 whatsapp 链接 - 图像、文本等,根据 - 见下面的例子) 在此处输入图片说明

回答by Gabriel Krenn

It is not possible to share a link on WhatsApp the way you want to. You can only send a message with the full link like http://example.org/and WhatsApp will detect this as a link for you.

无法以您想要的方式在 WhatsApp 上分享链接。您只能发送带有完整链接的消息,例如http://example.org/WhatsApp 会将此检测为您的链接。

回答by user6099216

the question asked about an html based procedure (no js)

关于基于 html 的程序的问题(无 js)

The answer is that at this time, it is possible to send text + a link to be identified by WhatsApp.

答案是,这个时候可以发送文本+链接被WhatsApp识别。

it is not possible to send only a title which, when clicked, will be linked to the url itself.

不可能只发送一个标题,点击后将链接到 url 本身。

The syntax in the html is:

html中的语法是:

    @{var urlWhatsapp = "whatsapp://send?text=" + @ViewBag.OgTitle + " - " + @ViewBag.OgUrl;}

    <a class="fa fa-whatsapp" href="@urlWhatsapp" target="_blank"></a>

where the @ViewBag.OgTitle is the title and the @ViewBag.OgUrl is the full url (including http:// or https://)

其中@ViewBag.OgTitle 是标题,@ViewBag.OgUrl 是完整网址(包括 http:// 或 https://)

回答by Harshvardhan Singh Baghel

Try:

尝试:

<a href="https://web.whatsapp.com/send?l=en&phone=+91 0000000000&text=I want to 
order a website" target="blank"></a>

Where 0000000000will be your 10 digit mobile no. and text= will be your predefined message.

0000000000你的 10 位手机号码在哪里?和 text= 将是您的预定义消息。