-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconditionalLoading.html
More file actions
70 lines (64 loc) · 2.54 KB
/
conditionalLoading.html
File metadata and controls
70 lines (64 loc) · 2.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>FB Login Check + Load Scripts Conditionally</title>
<script type="text/javascript">
// this fn can totally remove messenger chat
var hideMessenger = function () {
document.getElementsByClassName('fb-chat-html')[0].style.display = 'none';
document.getElementsByClassName('fb-chat-html')[0].innerHTML = '';
document.getElementsByClassName('fb-chat-html')[0].innerText = '';
}
function show_login_status(network, status) {
if (status) {
// you can do something if login status is true
console.log('Facebook is Logged In & hence loading messenger chat')
} else {
// you can do something if login status is not true
console.log(`Facebook is not logged In & hence loading botstar's chat`)
//hides messenger
hideMessenger()
var script = document.createElement("script");
script.type = "text/javascript";
script.src = "https://digitaliz.in/botstar.js";
document.head.appendChild(script);
}
}
</script>
</head>
<body>
<!-- ADD ALL THE FACEBOOK's CHAT PLUGIN'S HTML INSIDE THIS DIV TAG -->
<div class="fb-chat-html">
<div id="fb-root"></div>
<div class="fb-customerchat" attribution="setup_tool" page_id="109007700695057" theme_color="#fa3c4c"
logged_in_greeting="Hi, how can we help you today?" logged_out_greeting="Hi, how can we help you today?"
greeting_dialog_display="hide"></div>
</div>
</body>
<footer>
<script type="text/javascript">
var appIdFb = "2673494026216198" // replace it with your own facebook app id
window.fbAsyncInit = function () {
FB.init({ appId: appIdFb, status: true, cookie: true, xfbml: true, version: 'v3.2' });
FB.getLoginStatus(function (response) {
console.log(response, "this is response")
if (response.status != "unknown") {
show_login_status("Facebook", true);
} else {
show_login_status("Facebook", false);
}
});
};
// Below fn loads the FB's SDK + Customer Chat Plugin Asynchronously
(function (d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s); js.id = id; js.async = true;
js.src = "https://connect.facebook.net/en_US/sdk/xfbml.customerchat.js";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
</script>
</footer>
</html>