How to generate a "token" in the link bar with javascript?

1

I would like to know if you can generate random characters in the link on a page, without having to change the address of the link.

For example, when the person clicks the link, it will be sent to:

site.com/pages/pagina-de-destino.html

But I want the browser to display in the search bar:

site.com/pages/pagina-de-destino.html#access_token=(por volta de 160 caracteres aleatórios)

How to do this in JavaScript / HTML?

    
asked by anonymous 08.01.2016 / 06:17

1 answer

4

Within what has been asked, I think this resolves:

var result = '';
for (var i = 80; i > 0; --i) result += (Math.floor(Math.random()*256)).toString(16);

document.getElementById( 'link' ).href += '#access_token=' + result;
Ponha o mouse sobre o link e olhe a barra de status:<br>
<a id="link" href="http://pt.stackoverflow.com/a/107323/70">Link</a>

Just remember that anything in JS can be handled on the client side.

    
08.01.2016 / 07:23