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>
1

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

6 Comments

Thanks Dani, however when I click on the Buy Now button nothing happens, most probably I miss something, can you please take a look: aerobabe.com It's the first Buy Now button where I put your code. Thanks!
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.
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 <head> tag two sumo me scripts and a link: <link type="text/css" rel="stylesheet" href="//sumome-140a.kxcdn.com/virtual/ebf93592c0e80c06a16cbb032d576580392d7beb/client/js/../css/sme-popup.css"> EDIT: It shows me the popup only the first time I load the page. I don`t know how this should works.
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 [email protected]
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.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.