0

I have a Buy Now button and I want to execute a script after someone clicks on the button (include a popup). How can I do that?

This is my button html:

a class="btn-new page-scroll" href="#download" Buy Now

And this is my script I want to include in the html:

<script src="//load.sumome.com/" data-sumo-site-id="52c766d9109394d067f043544daf316657cac8d10a2b099638a1bfce5dfa90e6" async="async"></script>
Bernhard Barker
  • 54,589
  • 14
  • 104
  • 138
Andras
  • 1
  • 1
  • 1
  • Hope this helps [Link external script file onclick button](http://stackoverflow.com/questions/7789521/how-to-link-external-javascript-file-onclick-of-button) – Gaurav Mahawar Jul 30 '15 at 11:34

1 Answers1

0

For me this script doesn`t show any popup, but the script had worked after I clicked Buy Now. Here is the code:

<!DOCTYPE html>
<html>
<head>
    <!--Handling the click event I used the jquery library-->
    <script data-require="jquery@*" data-semver="2.1.4" src="http://code.jquery.com/jquery-2.1.4.min.js"></script>
</head>
<body>
    <!-- Buy Now -->
    <button class="btn-new page-scroll" href="#download" onclick="loadscript()">Buy Now</button>
    <!-- The click event will add the script into the head html tag.
    If you want to change the location look after other jquery selector. -->
    <script>
      function loadscript(){
        $('head')
            .append("<script src=\"//load.sumome.com/\" data-sumo-site-id=\"52c766d9109394d067f043544daf316657cac8d10a2b099638a1bfce5dfa90e6\" async=\"async\"><\/script>");
      }
    </script>

</body>
</html>

Use another jQuery selector if you want to add the script into another html tag that have an unique id or class.

Dani Feldman
  • 156
  • 2
  • 11
  • Thanks Dani, however when I click on the Buy Now button nothing happens, most probably I miss something, can you please take a look: http://www.aerobabe.com/ It's the first Buy Now button where I put your code. Thanks! – Andras Jul 31 '15 at 08:31
  • Also, if you are interested to give me private tips like this to help me finish the site and I would pay you on a hourly base, that would be awesome! Just give me your email address and I will drop you a mail. – Andras Jul 31 '15 at 08:35
  • The proof that the code works is that when you click the button, the SumoMe "tab" appears at the right-top side of the page. I have checked it with Inspect Element, and exectly the click event adds to the end of your tag two sumo me scripts and a link: EDIT: It shows me the popup only the first time I load the page. I don`t know how this should works. – Dani Feldman Jul 31 '15 at 08:58
  • Wow amazing, yes it does! I have set-up in somome the popup to appear after 0 seconds and for each time someone clicks on the button, amazing! Are you interested in tasks like this? If yes, drop me an email to andris.nemes@gmail.com – Andras Jul 31 '15 at 09:08
  • I am really happy to hear(read) that but note that I am only an IT student. Give me a chance to try that and we will see if i`m good enough in that. Is it ok if I write to you after 4-5 hours when I come to home? At this moment I am working. – Dani Feldman Jul 31 '15 at 09:28
  • Sure, thank you! I don't need someone professional, I look for someone who is creative and look after stuff. Thanks! – Andras Jul 31 '15 at 11:07