how do I get the page link

2

I want to create a share button to put on other sites like facebook or twitter and for that I need when I click the button it saves the url and sends it to my email, how do I do it?

    
asked by anonymous 15.08.2015 / 00:55

1 answer

1

With this you can get the url

var url = window.location.href.toString();

Here is a simple example so that when the user clicks the button, open a window with the url. Possible to be shared (Ctrl + C)!

var copyBtn = document.getElementById('copyBtn');

copyBtn.addEventListener('click', function(event) {

    /*Pega url*/
    var url = window.location.href.toString();

    /*seta para que a mesma possa ser compartilhada*/
    window.prompt("Pressione: Ctrl+C, para compartilhar a url", url);

});

Button html

<button id="copyBtn">Salvar URL!</button>
    
15.08.2015 / 01:28