how do I get the page link

Asked

Viewed 1,441 times

2

I want to create a share button to put on other sites, such as facebook, or twitter and for that I need that when I click the button save the url and send to my email, how do I do this?

  • java != javascript (http://answall.com/revisions/80920/1)

  • Use relevant tags to doubt, read this link: http://answall.com/help/how-to-ask

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. Making it possible to share (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>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.