[英]how to get JS alert when any web pages is shared in google plus or any social media, in codeigniter?
當我的任何網頁在諸如google plus,twitter,facebook等社交媒體上共享時,我都試圖顯示警報。 由於我對JS的了解很少,因此我需要一些幫助。 這是我從Google那里獲得的用於共享頁面的代碼。
<!-- Place this tag in your head or just before your close body tag. -->
<script src="https://apis.google.com/js/platform.js" async defer>
</script>
<!-- Place this tag where you want the share button to render. -->
<div class="g-plus" data-action="share"></div>
我想添加顯示諸如“頁面正在共享”之類的消息的警報。 我怎樣才能做到這一點。 任何幫助都值得贊賞。 謝謝
看我的編輯
<html>
<head>
<title>Your Website Title</title
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.0/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.10.2.js"></script>
<link rel="stylesheet" href="http://cdnjs.cloudflare.com/ajax/libs/jquery.bootstrapvalidator/0.5.3/css/bootstrapValidator.min.css"/>
<script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/jquery.bootstrapvalidator/0.5.3/js/bootstrapValidator.min.js"> </script>
</head>
<body>
<script>
buttons = document.querySelectorAll('[data-action]');
for ($i=0, len = buttons.length; $i < len; $i++) {
buttons[$i].addEventListener("click", function() {
alert("Thank you for sharing!");
}
}
>
</script>
<!-- Place this tag in your head or just before your close body tag. -->
<script src="https://apis.google.com/js/platform.js" async defer></script>
<!-- Place this tag where you want the share button to render. -->
<div class="g-plus" data-action="share" data-height="15"></div>
</body>
您可以在按鈕上放置事件偵聽器,以在用戶單擊按鈕時彈出警報。
// makes a nodelist of all buttons with the `data-action` attribute
buttons = document.querySelectorAll('[data-action]');
//iterates through the nodelist and adds the click function to each
for ($i=0, len = buttons.length; $i < len; $i++) {
buttons[$i].addEventListener("click", function() {
alert("Thank you for sharing!");
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.