Sorry, if this is a stupid question, I'm new to JavaScript. I'm trying to create links which will automatically update according to the page you're on. It worked fine when I just had one of them, but apparently, the first link also gives me the same output as the first one. Here's what I'm trying to achieve:
<html>
<head>
<!-- QR API generator call -->
<script>
baseurl="https://api.qrserver.com/v1/create-qr-code/?size=150x150&data="
function buildQR(item)
{
item.href=baseurl+window.location.href;
return true;
}
</script>
<!-- Sharing append link via JavaScript -->
<script>
baseurl="whatsapp://send?text="
function buildURL(item)
{
item.href=baseurl+window.location.href;
return true;
}
</script>
</head>
<body>
<a onclick="return buildQR(this)" href="">Generate QR</a>
<a onclick="return buildURL(this)" href="" data-action="share/whatsapp/share">Share on WhatsApp</a>
</body>
</html>
Thanks for helping me out.
P.S. I'm trying to achieve this, but with two links this time.
onclick, get your elements and thenaddEventListenerwhatever it needs - also, unless it's a true link, don't use<a>, use<button>because that's what it is, and then use CSS to style that however it needs to look. Also, say what kind of variable you're using.var?let?const? etc.<!doctype html>at the top to indicate this is true HTML5, you're missing a charset meta and a title, all that JS should be in its own file so you can load it with<script src="..." defer></script>, etc. -- it just looks like the kind of HTML/JS that highly outdated tutorials/books would teach you to use.