Hello,
As a novice to Webflow, I wondered if it’s possible to launch Javascript from a button?
Thanks, Jason
Hello,
As a novice to Webflow, I wondered if it’s possible to launch Javascript from a button?
Thanks, Jason
Yes, it’s possible. What are you trying to do?
Could be as simple as
<script>
$('#my-button-id').click(function() {
alert('button clicked');
});
</script>
Yes, but how do we put that code into the button. There is no Embed code option for a button.
I tried the other options to hide my email address from spambots shown here:
https://www.smartlabsoftware.com/howto/hide-email-spambots.htm
But none of them get through to the published page.
Webflow really needs to help us with avoiding email gathering spambots
I have to confess to not being amazing with scripts, but I believe that the example samliew wrote above (please correct me if I’m wrong) requires you to give your button and ID of, for argument’s sake, “my-button-id”.
You could of course change this, e.g. to “button”, you would just need to update that part of the code accordingly. The script itself would be embedded into the “custom code” field in your page settings.
Hope I’ve interpreted your example correctly @samliew!
Thanks @Andy_Vaughan - I managed to get the code to run by changing the button type to URL and having no URL. Rather cludgy. Yes I gave the button a matching ID. Now I need to get the javascript to do what I wanted - to call the mailclient - the code above creates a new html page with the email link. Looks like its obfiscating the email address from spambots, but really I’d prefer webflow just puts a tickbox next to any entered email addresses - tick to hide this email address from spambots
Nice one, I’m glad you got it sorted