I created a product-based service website. I need my customer to get quotes from the website to my WhatsApp.
Example:
<button>
<a href=" https://api.whatsapp.com/send? phone=whatsappnumber&text=The current URL of the website... I need a quote for this product" >
Send a quote on WhatsApp
</button>
How to get the current URL of the website? Please assist me.
3
Answers
The
window.location
object can be used to get the current page address (URL) and to redirect the browser to a new page.window.location.href
returns the href (URL) of the current pagewindow.location.hostname
returns the domain name of the web hostwindow.location.pathname
returns the path and filename of the current pagewindow.location.protocol
returns the web protocol used (http: or https:)window.location.assign()
loads a new documentTo get the current URL of the website, you can use the
window.location.href
property in JavaScript. You can then add this value to the text parameter in the WhatsApp link as follows:This will send a message to your WhatsApp number with the text "I need a quote for this product" followed by the current URL of the website.
This would work without an anchor tag.