In this post, we are going to learn the logic behind the share buttons displayed on the websites which can be used to share a post or the complete URL of the site on other social media platforms. We will be going through this in several steps for understanding.
Step 1: First, we need to create an HTML file that will display everything on the browser.
- Here the ‘window‘ is a global object which consists of various properties out of which location is one such property and the href property provides us the complete URL with the path and the protocol used.
Step 3: We don’t want the URL to be displayed as soon as the browser window loads instead we want it to be displayed when we click the button. So we will add an event listener to the button and then display the URL when the button is clicked
Step 4: Now the link is displayed when the button is clicked, but we don’t need a link to the current page but a link that shares the current webpage on a social media platform. So we update the code as follows.
- How to add whatsapp share button on a website ?
- Get the current URL using jQuery?
- How to get the current URL using AngularJS ?
- Java Program to Display Current Hour and Current Minute
- How to create a radio button similar to toggle button using Bootstrap ?
- How to share code between Node.js and the browser?
- How to share data between controllers in AngularJS ?
- Fair-share CPU scheduling
- button tag vs input type="button" attribute
- How to set radio button checked by button click in AngularJS ?
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.