So say we have an a tag in the page
<a href="www.url1.com">url1</a>
How can I set my cookie to www.url1.com
with javascript
onclick
?
So say we have an a tag in the page
<a href="www.url1.com">url1</a>
How can I set my cookie to www.url1.com
with javascript
onclick
?
Say the id
of your <a>
tag is myUrl
, then you can get the href
value by
var myUrl = document.getElementById('myUrl').getAttribute("href");
You can set the cookie using
document.cookie = "href=" + myUrl;
JSFiddle : https://jsfiddle.net/quttmdx5/