簡體   English   中英

節目 <div> 分享后/喜歡在Twitter / Facebook / Instagram上

[英]Show <div> after share/like on twitter/facebook/instagram

我找到了很多地方來解釋如何使用CSS和javascript顯示/隱藏div內容,但這並不是我想要的。

我正在嘗試獲取我的網站www.gadgetster.ca,以向在5個社交媒體網站中的3個網站上共享/喜歡該網站的用戶提供唯一生成的促銷代碼。

例如,如果您單擊facebook,twitter和instagram,然后按照/類似,則會彈出一個窗口詢問您的電子郵件,在電子郵件中它將發送促銷代碼(我將手動發送給自己)。 希望有道理...

任何幫助表示贊賞!

使用Javascript跟蹤用戶到目前為止的點擊次數,然后如果他們單擊3,則顯示促銷div? 在不提供任何代碼的情況下,我所能做的就是提供一個可能不是您想要的模型……

JSfiddle: http : //jsfiddle.net/bkw3L/1/

HTML,

<div id="promo" style="display: none"> Your promo code is ___ </div>

<a href="#" class="likeButton"> Like on Facebook  </a>
<a href="#"  class="likeButton"> Like on Twitter  </a>
<a href="#"  class="likeButton"> Like on Flicker  </a>
<a href="#"  class="likeButton"> Like on Google+  </a>
<a href="#"  class="likeButton"> Like on Foobar  </a>

Javascript

  // Keep track of which links the user clicked
var clickedLinks = [];

$(document).ready(function() {
    $(".likeButton").click(function(e) {
        var clickedLink = e.currentTarget.innerText;

        // If they haven't clicked this link before, add it to array
        if (clickedLinks.indexOf(clickedLink) == -1) {
            clickedLinks.push(clickedLink);

            // If they've clicked 3, show the div
            if (clickedLinks.length == 3) {
                $("#promo").show();   
            }
        }
    });   
});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM