Generate a SVG button that allows you to get upvoted anywhere.
👁️🗨️ Generate my upvote button ⬆️
Do you like Upvote Anywhere? If you do, please give it an upvote. |
<img id="upvoteBtn" src="https://wp2aqcqkj5.us.aircode.run/show?id=64dc8e2885f13fbcd52be970" width="35" style="vertical-align: bottom;cursor:pointer;"> Do you like Upvote Anywhere? If you do, please give it an upvote.
<script>
upvoteBtn.addEventListener('click', async (event) => {
event.preventDefault();
await fetch('https://wp2aqcqkj5.us.aircode.run/upvote', {
method: 'POST',
headers: {
'content-type': 'application/json',
},
body: JSON.stringify({id: '64dc8e2885f13fbcd52be970'}),
});
upvoteBtn.src = "https://wp2aqcqkj5.us.aircode.run/show?id=64dc8e2885f13fbcd52be970&t=" + Date.now();
});
</script>
Since Upvote Anywhere requires using cookies to track upvote status, when it's used on third-party websites and operated through fetch, it relies on the other party's CORS policy. For instance, CodePen's policy doesn't allow cross-site cookies, which means Upvote Anywhere can't record the voted status. However, we can use a GET request to https://wp2aqcqkj5.us.aircode.run/upvote to store the cookie on the original site, then redirect back to the target URL, just as we've done in our GitHub README.
Upvote Anywhere is build on AirCode.
You can easily get a copy and launch your app on AirCode by clicking the button below.