whatsapp与当前网址的聊天按钮

时间:2018-05-17 15:57:11

标签: javascript html

< a href =" https://api.whatsapp.com/send?phone = 601005108869& text = {current webpage url}"> whastsapp me now now< / a>

如何让代码 自动填写{当前网页网址}?

例如, 访客访问我的网站 当前网址>> http://sample.com/1-1

代码将填写如下

< a href =" https://api.whatsapp.com/send?phone = 60105108869& text = http://sample.com/1-1"> whastsapp me now now< / A>

1 个答案:

答案 0 :(得分:1)

使用<a id="whatsapp-button">Chat With Us</a> 获取当前位置并相应地生成网址文字。

假设你的html中有一个按钮:

// Get the element
$link = document.querySelector("#whatsapp-button");

// Generate url
$url = "api.whatsapp.com/send?phone=601005108869&text=" + window.location.href;

// Set url attribute of the link
$link.setAttribute('href', $url);

在javascript文件中:

&#13;
&#13;
$( document ).ready()
&#13;
&#13;
&#13;

确保您的javascript文件在页面加载后运行,这意味着要么在关闭body标记之前将其放置,要么使用jQuery的let filePath: String = Bundle.main.path(forResource: "shared", ofType: "json")! let fileUrl: URL = URL(fileURLWithPath: filePath) do { try jsonData.write(to: fileUrl, atomically: false, encoding: .utf8) do { let newData = try String(contentsOf: fileUrl, encoding: .utf8) print("New Data: \(newData)") } catch { print("Failed to read updated file data") } } catch { print("Failed to write data to file") } 方法。