I have added the Facebook chat plugin through this code generated from facebook.com
<!-- Load Facebook SDK for JavaScript -->
<div id="fb-root"></div>
<script>(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s); js.id = id;
js.src = 'https://connect.facebook.net/en_US/sdk/xfbml.customerchat.js';
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>
<!-- Your customer chat code -->
<div class="fb-customerchat"
attribution=setup_tool
page_id="124030157608968">
</div>`
However I run a Pagespeed test in Google Chrome and the results are disaster.
Any suggestions how to solve this problem?
Thank you very much!
Same issue. No matter if you initialize it in an async manner or not, it literally kills the Page speed index of your website!
Here's an approach I did in order to fully go around this disaster.
I placed a fake 🙄 Messanger button at the bottom right of the page:
<svg id="fb-messanger-fake-button" width="60px" height="60px" viewBox="0 0 60 60" cursor="pointer">
<g stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
<g>
<circle fill="#00B2FF" cx="30" cy="30" r="30"></circle><svg x="10" y="10">
<g transform="translate(0.000000, -10.000000)" fill="#FFFFFF">
<g id="logo" transform="translate(0.000000, 10.000000)">
<path
d="M20,0 C31.2666,0 40,8.2528 40,19.4 C40,30.5472 31.2666,38.8 20,38.8 C17.9763,38.8 16.0348,38.5327 14.2106,38.0311 C13.856,37.9335 13.4789,37.9612 13.1424,38.1098 L9.1727,39.8621 C8.1343,40.3205 6.9621,39.5819 6.9273,38.4474 L6.8184,34.8894 C6.805,34.4513 6.6078,34.0414 6.2811,33.7492 C2.3896,30.2691 0,25.2307 0,19.4 C0,8.2528 8.7334,0 20,0 Z M7.99009,25.07344 C7.42629,25.96794 8.52579,26.97594 9.36809,26.33674 L15.67879,21.54734 C16.10569,21.22334 16.69559,21.22164 17.12429,21.54314 L21.79709,25.04774 C23.19919,26.09944 25.20039,25.73014 26.13499,24.24744 L32.00999,14.92654 C32.57369,14.03204 31.47419,13.02404 30.63189,13.66324 L24.32119,18.45264 C23.89429,18.77664 23.30439,18.77834 22.87569,18.45674 L18.20299,14.95224 C16.80079,13.90064 14.79959,14.26984 13.86509,15.75264 L7.99009,25.07344 Z">
</path>
</g>
</g>
</svg>
</g>
</g>
</svg>
... aaaand I positioned it with CSS on the bottom right corner, EXACTLY where the real Messanger button will appear (based on your configuration):
#fb-messanger-fake-button {
position: fixed;
bottom: 24px;
right: 24px;
z-index: 100;
transition: opacity 0.3s;
}
Using jQuery (in my case) or just plain JavaScript (if you want), implement logic that injects the Facebook SDK and initiates the Messanger plugin ONLY when the user clicks on our fake Messanger button:
// Facebook SDK for JavaScript inject code
function injectFbSdkAsync(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s); js.id = id;
js.src = 'https://connect.facebook.net/en_US/sdk/xfbml.customerchat.js';
fjs.parentNode.insertBefore(js, fjs);
};
$(function() {
const $fbMessangerFakeButton = $('#fb-messanger-fake-button');
$fbMessangerFakeButton.on('click', function(){
// Fades out the fake button a bit, to indicate "loading"
$fbMessangerFakeButton.css({ opacity: 0.4 });
// Inject the Facebook SDK in async manner:
injectFbSdkAsync(document, 'script', 'facebook-jssdk');
// Callback on Facebook SDK init, that fires up the Messanger plugin
window.fbAsyncInit = function() {
FB.init({ xfbml: true, version: 'v8.0' });
// Callback when Facebook SDK finish up with rendering
FB.Event.subscribe('xfbml.render', function(){
// Immediately toggle opening the Facebook Messanger,
// as if the user clicked the real Messanger button.
FB.CustomerChat.show(true);
// Hide the fake button, so that only the real one remains!
$fbMessangerFakeButton.css({ display: 'none' });
});
};
});
});
And that's it! Your page speed index is back to normal.
I like Kaloyan's approach very much. Thank you! It is extremely useful and helping in website performance, which becomes evidently better.
I've improved the fake button with a little spinner inside, as loading indicator - just for better UX.
Also wrapped SVG with button tag (for better a11y, I believe), and don't use jQuery anymore.
Messenger Fake Button
Full code, to hook at the end of the page (in footer maybe).
<button id="fb-messenger-fake-button">
<svg xmlns="http://www.w3.org/2000/svg" width="60" height="60" viewBox="0 0 1024 1024" aria-hidden="true">
<circle fill="#00B2FF" style="fill: var(--msgr-color, #00B2FF)" cx="512" cy="512" r="512"/>
<g id="spinner" fill="#fff"><circle cx="512" cy="239" r="47"/><circle cx="375" cy="275" r="47" fill-opacity="0.9"/><circle cx="275" cy="375" r="47" fill-opacity="0.8"/><circle cx="239" cy="512" r="47" fill-opacity="0.7"/><circle cx="275" cy="649" r="47" fill-opacity="0.6"/><circle cx="375" cy="749" r="47" fill-opacity="0.5"/><circle cx="512" cy="785" r="47" fill-opacity="0.4"/><circle cx="649" cy="749" r="47" fill-opacity="0.3"/><circle cx="749" cy="649" r="47" fill-opacity="0.2"/><circle cx="785" cy="512" r="47" fill-opacity="0.1"/></g>
<path id="logo" fill="#fff" d="M512 171c192 0 341 141 341 331S704 833 512 833c-35 0-68-5-99-13-6-2-12-1-18 1l-68 30c-17 8-37-5-38-24l-2-61c0-7-4-14-9-19a324 324 0 01-107-245c0-190 149-331 341-331zM307 599c-10 15 9 32 24 21l107-82c8-5 18-5 25 0l80 60c24 18 58 12 74-14l100-159c10-15-9-32-24-21l-107 82c-8 5-18 5-25 0l-80-60a51 51 0 00-74 13L307 599z"/>
</svg><span class="screen-reader-text">Enable chat via Messenger</span>
</button>
<!-- Messenger Chat plugin Code -->
<div id="fb-root"></div>
<!-- Your Chat Plugin code -->
<!-- Put the ID of your page on Facebook, at least -->
<div class="fb-customerchat"
attribution=setup_tool
page_id="000000000000000"
theme_color="#00B2FF"
logged_in_greeting="Hi! How can I help you?"
logged_out_greeting="Hi! How can I help you?">
</div>
<script>
// Facebook SDK for JavaScript inject code
// Change language part to yours, e.g.: en_US > pl_PL
function injectFbSdkAsync(d, s, id) {
var js,
fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s);
js.id = id;
js.src = "https://connect.facebook.net/en_US/sdk/xfbml.customerchat.js";
fjs.parentNode.insertBefore(js, fjs);
}
var fbMessengerFakeButton = document.getElementById('fb-messenger-fake-button');
fbMessengerFakeButton.addEventListener('click', function() {
// Once #fb-messenger-fake-button is clicked triggers animated spinner inside it
// See CSS, and SVG structure inside the button
this.classList.add('active');
// Inject the Facebook SDK in async manner:
injectFbSdkAsync(document, "script", "facebook-jssdk");
// Callback on Facebook SDK init, that fires up the Messenger plugin
window.fbAsyncInit = function () {
FB.init({ xfbml: true, version: "v10.0" });
// Callback when Facebook SDK finish up with rendering
FB.Event.subscribe("xfbml.render", function () {
// Opening the Facebook Messenger
FB.CustomerChat.show(true);
// Hide the fake button, so that only the real one remains!
fbMessengerFakeButton.style.display = 'none';
});
};
});
</script>
CSS
#fb-messenger-fake-button {
position: fixed;
z-index: 100;
bottom: 24px;
right: 24px;
padding: 0 !important;
border-radius: 50%;
/* you may use a color of your theme */
--msgr-color: transparent;
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
cursor: pointer;
transition: all 0.3s;
}
#fb-messenger-fake-button svg {
display: block;
}
#fb-messenger-fake-button.active #logo {
opacity: 0;
}
#fb-messenger-fake-button.active #spinner {
animation: spin 3s linear infinite;
transform-origin: center;
}
#keyframes spin {
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
}
Where to setup Messenger chat at Facebook
Go to your page on Facebook:
Settings → Messaging → Add Messenger to your website → Get Started
There, most of all, you need to put your website domain.
Put the whole code on the very bottom of the source code
Save https://connect.facebook.net/en_US/sdk/xfbml.customerchat.js locally, implement it from there with defer.
Related
None of our games is playable from Firefox on some computers. Until yesterday, we didn't have the chance to reproduce the error, but now we can on two of our office computers. As a test, this is the link of one of our games which won't load (https://apps.facebook.com/magicquesttcg/)
The only setup where we have been able to reproduce the issue is the following:
OS: Windows 10 (64 bits)
Browser: Mozilla Firefox v58.0 (https://ftp.mozilla.org/pub/firefox/releases/58.0/win64/en-US/)
Flash Version installed: v28.0 (latest). We have tried with several flash versions, all of them have the same impact.
When loading the website it will display the "You don't have Flash installed message" (even if it's installed)
We are embedding the swf the simplest way possible, but we have also tried it using swfObject, nothing. It just won't work.
I hope you can help us!
Here's the index.html we are currently using:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:fb="http://www.facebook.com/2008/fbml" lang="en" xml:lang="en">
<head>
<script type="text/javascript">
var v = "\?v=1.5.4.028"
var platform="fb";
<!-- #return whether the current platform is Facebook or not -->
function isFacebook(){return platform == "fb";}
</script>
<!-- Add FACEBOOK Script (Conditionally) -->
<script type="text/javascript">
if(isFacebook())
{
(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/en_US/all.js";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
}
</script>
<title>Magic Quest: TCG</title>
<meta name="google" value="notranslate" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style type="text/css" media="screen">
html, body { height:100%; }
body { margin:0; padding:0; overflow:auto; text-align:center;
background-color: #000000; }
object:focus { outline:none; }
#flashContent { display:none; box-shadow:0px 0px 60px black;}
</style>
<!-- Enable Browser History by replacing useBrowserHistory tokens with two hyphens -->
<!-- BEGIN Browser History required section -->
<link rel="stylesheet" type="text/css" href="history/history.css"/>
<script type="text/javascript" src="history/history.js"></script>
<!-- END Browser History required section -->
<!-- Include support librarys first -->
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/swfobject/2.2/swfobject.js"></script>
<script type="text/javascript" src="swfobject.js"></script>
<script type="text/javascript">
var cssStyle = (isFacebook()) ? "display:block;text-align:left;box-shadow:0px 0px 60px;" : "display:block;text-align:left;";
// For version detection, set to min. required Flash Player version, or 0 (or 0.0.0), for no version detection.
var swfVersionStr = "18.0.0";
// To use express install, set to playerProductInstall.swf, otherwise the empty string.
var xiSwfUrlStr = "playerProductInstall.swf";
var flashvars = (isFacebook()) ? {} : kongregateAPI.flashVarsObject();
var params = {};
params.quality = "high";
params.bgcolor = "#000000";
params.allowscriptaccess = "always";
params.allowfullscreen = "true";
params.allowFullScreenInteractive = "true";
params.wmode = "direct";
var attributes = {};
attributes.id = "FSPreloader";
attributes.name = "FSPreloader";
attributes.align = "middle";
attributes.type = "application/x-shockwave-flash";
swfobject.embedSWF(
"FSPreloader.swf" + v, "flashContent",
"800", "600",
swfVersionStr, xiSwfUrlStr,
flashvars, params, attributes);
// JavaScript enabled so display the flashContent div in case it is not replaced with a swf object.
swfobject.createCSS("#flashContent", cssStyle);
</script>
<style media="screen" type="text/css">#flashContent {box-shadow:0px 0px 60px black} </style>
</head>
<body id="body">
<div id="fb-root"></div>
<script>
window.fbAsyncInit = function() {
FB.init({
appId : 'XXXXXXXXXXXXXXXXXXX',
xfbml : true,
version : 'v2.11'
});
// ADD ADDITIONAL FACEBOOK CODE HERE
};
(function(d, s, id){
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) {return;}
js = d.createElement(s); js.id = id;
js.src = "https://connect.facebook.net/en_US/sdk.js";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
</script>
<center>
<div style="box-shadow:0px 0px 60px; -moz-box-shadow: 0px 0px 60px; -webkit-box-shadow: 0px 0px 60px; width:800px;">
<div id="flashContent">
<p style="background-color:black;">
<font color="red">
<b> To view this page ensure that Adobe Flash Player version
18.0.0 or greater is installed. Make sure to install it by downloading it from <strong>here</strong>
(Right click and Select "Open link on new tab" if single click does not work). If after installing doesn't work, make sure to "Activate always" Flash extension on your browser and untick the "Block Dangerous and intrusive Flash Content".
</b>
</font>
</p>
Get Flash
</div>
</div>
</center>
</body>
</html>
Thanks beforehand
Pasting here a link to the solution we found in case anyone has the same issue:
https://support.mozilla.org/en-US/questions/1202849#answer-1073221
I'm trying to add several facebook share buttons on the page, but calling the "share" functions, that shares the current material on facebook, works only once at the page, after one click, you have to reload the page for another sharing.
Here is my HTML:
<button class="share js-share-btn">Share</button>
<button class="share js-share-btn">Share</button>
<button class="share js-share-btn">Share</button>
CSS:
body {
text-align: center;
}
.share {
display: inline-block;
width: 40px;
height: 20px;
margin: 20px;
}
And JS:
$(".js-share-btn").each(function(){
$(this).on('click', function(event){
event.preventDefault();
fbShare('title','description');
return false;
})
});
function fbShare(title, description, image) {
(function(d, s, id){
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) {return;}
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/en_US/sdk.js";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
window.fbAsyncInit = function() {
FB.init({
appId : 'id',
xfbml : true,
version : 'v2.8'
});
FB.ui({
method: 'share_open_graph',
action_type: 'og.shares',
action_properties: JSON.stringify({
object : {
'og:url': 'http://dla.dev',
'og:title': title,
'og:description': description,
'og:image': image
}
})
}, function(response){});
};
}
Here is link on codepen: http://codepen.io/jumkarto/pen/YprMbK
If anyone knows the solution of my problem, I would really appreciate you help.
Add this code in the very top of body :
<div id="fb-root"></div>
<script async defer crossorigin="anonymous" src="https://connect.facebook.net/cs_CZ/sdk.js#xfbml=1&version=v3.3"></script>
after that place Share Button :
<div class="fb-share-button" data-href="[your_page]" data-layout="button_count" data-size="large">
<a target="_blank"
href="https://www.facebook.com/sharer/sharer.php?u=[your_page];src=sdkpreparse"
class="fb-xfbml-parse-ignore">SdÃlet
</a>
</div>
And just call function FB.XFBML.parse(); dynamicaly instead of reloading the page.
FB.XFBML.parse(); <-- fixed for me
On my website the Facebook Like box disappears after exactly 45 seconds. I even put just the Like box code in it's own html document, verbatim from what I got from the developers site, but still the same outcome, so it seems like a Facebook issue, but I am not sure. I have tried on IE 11, FF 23.0.1, and the latest Chrome but it's the same thing.
<div id="fb-root"></div>
<script>(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[1];
if (d.getElementById(id)) return;
js = d.createElement(s); js.id = id;
js.src = "http://connect.facebook.net/en_US/all.js#xfbml=1";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>
<div class="fb-like-box" data-href="https://www.facebook.com/Awesome.Animals" data-width="300"
data-height="375" data-colorscheme="light" data-show-faces="false" data-
header="false" data-stream="true" data-show-border="false"></div>
It happens because of NoScript. It will be fine if you allow all of Facebook's domains get through (both facebook.com and facebook.net).
For some reason the Facebook JavaScript meddles with the size of the Facebook generated iframe after 45 seconds. Check your browser developer console. Do you see a warning message?
fb:share_button failed to resize in 45s
As a fix, use CSS to force the iframe to be a certain height and width like so:
.fb-like-box iframe {
width: 110px !important;
height: 20px !important;
}
Since 2 weeks I am stuck with the social plugin commentbox. I managed to install the "Hike - Free Tab Builder" on my FB Fanpage and inserted there a HTML code with text and I also included a cuple of boxes there. In order to moderate those boxes I made an App (commentbox) to get an AppID and I did everything asked in the fb.developers tutorial. I put the asked IDs as meta command in the "head" section and put anything else right behind the "body" tag.
It never manages to get connected to the Moderation Tool and I cannot say whats wrong. I am working on this for 2 weeks now, I asked and searched around for answers but without succes. Maybe anyone here can give the answer.
Here is some part of the code I wrote:
<!DOCTYPE html>
<html>
<head>
<meta property="fb:admins" content="{10000113xxxxxxx}"/>
<meta property="fb:app_id" content="{20368994xxxxxxx}"/>
<title>Research</title>
<style type="text/css">
P {font-family: arial; color: rgb(0, 0, 102); font-size: 1}
H2 {font-family: arial; font-size: 4; color: rgb(153, 0, 0); font: bold}
H3 {font-family: arial; font-size: 3; color: rgb(153, 0, 0); font: bold}
HR {font-family: arial; width: auto}
</style>
</head>
<body>
<div id="fb-root"></div>
<script>
window.fbAsyncInit = function() {
FB.init({
appId : '203689xxxxxxx', // App ID
channelUrl : '//channel.html', // Channel File
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
xfbml : true // parse XFBML
});
// Additional initialization code here
};
// Load the SDK Asynchronously
(function(d){
var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
if (d.getElementById(id)) {return;}
js = d.createElement('script'); js.id = id; js.async = true;
js.src = "//connect.facebook.net/en_US/all.js";
ref.parentNode.insertBefore(js, ref);
}(document));
</script>
<div id="fb-root"></div>
<script>(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/de_DE/all.js#xfbml=1&appId=2036899xxxxxxx";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>
<h2>Contents</h2>
(...)
<div class="fb-comments" data-href="https://www.facebook.com/(...)/app_151503908244383" data-num-posts="10" data-width="785"></div>
(...)
</body>
</html>
Any idea whats wrong here?
you have to define og:url, og:title and og:img.
http://developers.facebook.com/tools/debug is helpfull tool. Just write your url and let it say something to you.
I am using facebook like send, tweet and Google plus like this. I am specifying width 320 for facebook div and width 105 for tweet. But the facebook and tweet button's
(div/iframe) should be automatically increased and decreased on their own based on the content width inside them. Can someone suggest me a way to achieve this. My main
idea is to cut the gap between these sections.
<script type="text/javascript">
var SnImpl= "<%=SnImpl%>";
if (SnImpl == "true") {
(document, 'script', 'facebook-jssdk');
(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/en_US/all.js#xfbml=1";
fjs.parentNode.insertBefore(js, fjs);
} (document, 'script', 'facebook-jssdk'));
(function() {
var scrGooglePlus = document.createElement('script');
scrGooglePlus.type = 'text/javascript';
scrGooglePlus.async = true;
scrGooglePlus.src = 'https://apis.google.com/js/plusone.js';
var scrWriter = document.getElementsByTagName('script')[0];
scrWriter.parentNode.insertBefore(scrGooglePlus, scrWriter);
})();
}
<div class="fb-like" data-href="<%=strSNURL %>" data-send="true"
data-width="320px" data-show-faces="false">
</div>
<iframe allowtransparency="true" frameborder="0" scrolling="no" src="//platform.twitter.com/widgets/tweet_button.html?url=<%=strSNURL %>&via=SomeOne&text=Something" style="width: 105px; height: 25px;"></iframe>
<g:plusone href="<%=strSNURL %>"></g:plusone>
You need to know ahead of time how wide to make the plugins.
If you specify 320px for Facebook, facebook's iFrame will become 320px. Facebook doesn't even know how much minimum width the iframe's contents will take, so it just follows your orders of 320px. (http://developers.facebook.com/docs/reference/plugins/like/) I would suggest trying to specify 120px and also changing the layout style to "button_count" as this one is fairly narrow as compared to the default "standard". "box_count" will be the most narrow choice of them all, taking up only 50px width.
For twitter (https://dev.twitter.com/docs/tweet-button), you can specify "vertical" for the count property and this will skinny it up to 58px wide.
For google (https://developers.google.com/+/plugins/+1button/), you can specify tall bubble to match the other two. This will give you a width of 50px.