Coupon Code Functionality [Beginner]

Creating a coupon website and lost in functionality. So what I want to achieve is when a user clicks on “Get Code”, I want the user to copy the code (popup) & then redirect to the respective website.

Any directions on how to do would be really helpful.


1 Like

Maybe you can share your current code and we’ll have a look at it? Or it could be that you don’t have a working code so that’s okay.

From my readings, it seems that you can use the Clipboard API or its alternatives to copy to clipboard. To redirect, modify window.location.href or use replace().

When the user clicks on “Get Code”, the onclick should call a function that’ll first copy the coupon code to the clipboard and then redirect once the copy is complete.

I’ve never tested this myself so I’m not sure if the above is the best approach.


Thank you for replying. As said, i do not have working code but I found two codes and breaking my head to get it.

Code 1: 
<a href="#" class="btn btn-default btn-code" data-toggle="tooltip" data-placement="bottom" onclick="copy_coupon_and_go_to_site('98227','EVR0KRGNTTFW');" data-original-title="" title=""> GET CODE</a>
function copy_coupon_and_go_to_site ( coupon_id,couponCode )
    var url = window.document.URL;
    var index = url.lastIndexOf("/");
    if(index > 0){
      var reload_url = url.substring(0,index);
      var reload_url = url;
              if(couponCode && couponCode != 'Get_Deal' && couponCode != 'Activate_Deal'){
          window.prompt("Copy to clipboard: Ctrl+C, Enter", couponCode);
      window.location.assign(reload_url+"/?couponid="+coupon_id); ( ""+coupon_id+"/" , "_blank" ) ;

Code 2: From a different website.
<a href="" target="_self" onclick="openpage('/index?coid=73')" rel="nofollow">
        <div class="coupon-box">
          <div class="code-container">
            <div class="code">
              <div class="coupon-hop">
                <div class="partial-code text-right">9</div>
                <div class="hide-btn">Show Code</div>

Will read the resources you shared as well. Thank you for the revert.

EDIT: Example - couponpa [dot] com. P.S. I’m not related to this site at all. Not sure if this is right way to have website mentioned here. Mods can delete this if i’m wrong,

1 Like

Nah, it seems fine to me. You’re not promoting anything nor does the site seem malicious (I could be wrong here).

I’ve looked at the site and from what I understand:

  1. Click “Show code & visit site”
  2. Copy coupon code by clicking the “Copy” button on the popup
  3. After clicking “Copy”, you will be redirected to the site to use the coupon with.

In, it doesn’t redirect and instead, it opens the site in a new tab.