This has been driving me completely nuts for months now. I have created an app for the sole purpose of displaying content customized for facebook from my company's website.
We want something like this: http://www.facebook.com/FarmersInsurance?sk=app_7146470109
But end up with this: http://www.facebook.com/DeltaFlexTravelers?sk=app_110411285713674
I can't get rid of the damn scroll bars! I've done everything that other answers to this kind of question suggest to no avail. I am explicitly setting the width and height using FB.Canvas.setSize(). nothing.
I am wondering if FB.Canvas.setSize() does not work when displaying the content as a page tab. If that is the case how do you get rid of the freakin' scrollbars on an app displayed as a page tab?
Even with the width set in IE I get scroll bars and cut off content. Had to cut it down to 510px. 520 is the max but different browsers may have different dpi settings. Either that or MS gave IE a different definition of a pixel.
Try creating a wrapper div that is the size you want (default 520x800 )and then set the overflow to hidden. Forces you to design within the space but got rid of the scrollbar issue for me. You'll probably also need to set the margin:0,padding:0 for that div as well. If you need more specifics you can look at http://facebook.com/xocialhost at the page tabs we've built. Feel free to look at the source stylesheet which is a modified version of the HTML 5 boilerplate that we've customized to work for our FB apps.
You need to do two things:
1. Use FB.Canvas.setSize(). As an extra hammer use the setAutoResize with a short delay.
2. Set your tab page CSS to overflow = hidden;
Here is the setSize Portion:
FB.Canvas.setSize();
}
function sizeChangeCallback() {
FB.Canvas.setSize();
}
FB.Canvas.setAutoResize(7);
And here is the CSS portion:
body {
margin: 0px;
padding: 0px;
overflow: hidden;
}
Did you try with setting up size? What I always do to get rid of scrollbars is to set 2 things:
Container of my app is always 520px width, and have overflow: hidden set
Height of tab I set with JS API is always bit bigger then actual HTML height.
It always work for me...
And this is the code I'm using:
window.fbAsyncInit = function() {
if(typeof(FB) != 'undefined') {
FB.init({
appId: 111111111111111, xfbml: true, status: true, cookie: true, oauth: true
});
FB.Canvas.setSize({ width: 760, height: 1250 });
}
};
(function() {
var e = document.createElement('script');
e.async = true;
e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';
document.getElementById('fb-root').appendChild(e);
}());
Related
I created a wordpress theme 810px wide to fit the new Page width. But I am getting scroll bars. How do I prevent or remove the scroll bars?
Thanks!
The FB guideline on managing scrolls bars is to use FB.Canvas.setAutoGrow function from the JS SDK. Please understand that the theme you put together should preferably be within about 800px (our implementations have gone up til 802px and it has worked fine), but the height can grow as much and with the integration of FB.Canvas.setAutoGrow, you should see only one scrollbar - that on Facebook's own page which should cover your entire content.
You need to call FB.Canvas.setSize(); to remove vertical scroll bars. You will need to do his on document.ready, and any other time your page resizes. I advise against FB.Canvas.setAutoGrow(); as it's much more efficient to only call setSize() when needed.
You will need to call FB.init() prior to setSize(). If you were to use the sample code from the top of https://developers.facebook.com/docs/reference/javascript/ then you can call setSize() where it says
// Additional initialization code here
overflow:hidden;
Add this to the div's CSS.
First, set the height and and width (810px) of your page in the CSS added overflow: hidden then set them again in the first line of code here and replace the opening body tag with this:
(remember to replace YOURAPPID with your App Id too)
<body onload="FB.Canvas.setSize({width: 810, height: 910})">
<div id="fb-root"></div>
<script>
(function () {
var e = document.createElement('script');
e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js#xfbml=1&appId=YOURAPPID;
e.async = true;
document.getElementById('fb-root').appendChild(e);
} ());
</script>
This is not a scrollbars question. Here is the thing:
You load your Facebook canvas app and do a FB.Canvas.setSize({height:900}); (works)
You move to another section of your app (some link) and then do a FB.Canvas.setSize({height:1300});
The second step doesn't work. The app iframe remains at 900px height.
What I need, is to change the canvas height dynamically after it has already been set. According to the Facebook documentation, this should work. They do not specify if you can or cannot change the canvas height once it has been set.
I've tried the same method on page tabs and it works, I can properly resize the height of the tab using setSize(), however, it seems like canvas pages behave differently (?).
This is the code I am using, right after opening the body tag:
<div id="fb-root"></div>
<script type="text/javascript">
<!--
window.fbAsyncInit = function() {
FB.init({appId: "XXXXXXXXXXXXXXXXXXXXX",
status: true,
cookie: true,
xfbml: true});
};
(function() {
var e = document.createElement("script"); e.async = true;
e.src = document.location.protocol +"//connect.facebook.net/en_US/all.js";
document.getElementById("fb-root").appendChild(e);
}());
window.fbAsyncInit = function() {
FB.Canvas.setSize({height:1300});
}
//-->
</script>
The designer made a Canvas app using different heights and so far its has been a pain to implement.
You're assigning different things to window.fbAsyncInit in two different places. You should just get rid of the second assignment and move the FB.Canvas.setSize call to right after the FB.init call (or replace the FB.init call, as you don't need it if you're only using the SDK for resizing; obviously keep it if you are doing auth stuff with it as well).
Facebook's mobile examples use the script: http://connect.facebook.net/en_US/all.js. This script adds to the div fb-root. My mobile site is 320px wide and I use the viewport meta setting. Including Facebook's script causes a big extra space on the right side of the actual content because it's settings it's contents to 575px wide. I tried including code to replace the 575px with 320px ("#fb-root").val().replace("575px","320px"); but that hasn't helped -- maybe I'm doing it wrong (using jQuery).
Anyone know how to restrict this to 320px?
Update:
Found a bug a report on this with two work-arounds:
Set status to false in the FB.init. I can verify that this does fix the problem for me, but breaks the ability for users to login.
Move <div id="fb-root"></div> directly under <body>. This didn't work for me.
Source:
http://bugs.developers.facebook.net/show_bug.cgi?id=18528
I used the following css style rule to beat this 575px #fb-root width problem:
#fb-root > div { left:-575px !important; }
That works because, if you locate the #fb-root node in, say, Firebug's HTML tree-viewer, you'll find that it contains a child div that is styled as follows:
position: absolute; top: -10000px; height: 0pt; width: 0pt;
i just set this in the css by default
#fb-root{display:none}
and when i need to use the FB dialogs(when calling FB.ui), i do this:
$('#fb-root').show();
and in the callback of the FB.ui, i do this
$('#fb-root').hide();
so here is an example:
var inviteFriend = function (msg) {
$('#fb-root').show();
FB.ui({
method: 'apprequests',
message: msg
}, function (response) {
$('#fb-root').hide();
console.log('sendRequest response: ', response);
});
},
this works for me, and i have tested on some devices.
The code you've provided seems to only replace the value in the code, which has, by that point, already fired. You might try to setting the width with jquery's .css() method on fb-root. Make sure this is fired after the fb js sdk is included, or put into the callback method if loading asynchronously.
Or just wrap it in another div, set its height and width, and the put overflow:hidden;
I created a custom facebook landing page using the same template I have used 3 times before. The problem is, this time, ther vertical scrollbar won't go away. This is the resizing code I have been using:
<script type="text/javascript">// <![CDATA[
window.fbAsyncInit = function() { FB.Canvas.setSize({ width: 520, height: 1200});}
function sizeChangeCallback() { FB.Canvas.setSize({ width: 520, height: 1200});}
// ]]></script>
and at the bottom of the page:
<div id="fb-root"></div>
<script src="http://connect.facebook.net/en_US/all.js" type="text/javascript"></script>
<script type="text/javascript">// <![CDATA[
FB.init({
appId : 'MY_APP_ID',
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
xfbml : true // parse XFBML
});
// ]]></script>
My CSS uses body {overflow: hidden;}, inside my app "auto resize" is selected. The issue is not that the ifarme won't resize (it does), it's that I have an empty vertical scrollbar on the right that won't go away.
Since the iframe design uses the whole 520px width, the empty vertical srollbar gives me the dreaded horizontal scrollbar. Judging by the width of the horizontal scrollbar, it's the vertical scrollbar causing it and not anything (that I can find or see) in the HTML/CSS making the page wider than 520px. The problem happens in IE8, IE7 and Firefox.
You can see the page here.
I have tried a few variations of the javascript code from a few different sources, but no luck. Not sure if this is something small I'm missing or if it's yet another facebook bug. This problem is not present on any of my other facebook iframe landing pages. After searching around for an answer and coming up with nothing, I've hit a wall with this one.
Its this code
html {
overflow-Y: scroll;
}
in your style.css style sheet thats causing the problem. When I inspect it with Chrome and remove that value, the scroll bars disappear.
I have this Facebook application profile page:
http://www.facebook.com/developers/editapp.php?app_id=122313254494566#!/apps/application.php?id=122313254494566
which is associated with my iframe-based Facebook application, Gem Spinner:
http://apps.facebook.com/gemspinner/
What I'm seeing is that, depending on the window height, my iframed content will appear with a fixed height and a scroll bar, instead of just flowing down the page (and off the bottom of the page, as necessary), as I would like. When I make the window shorter, the scroll bar appears; when I make the window taller, the scroll bar disappears. My understanding is that it's Facebook determining this height and adding the scroll bar (but maybe I'm wrong about that). In any case, I would appreciate any help in understanding this and letting my content flow down the page as necessary.
Well, I did a few things to get it to work.
(1) In my application settings, under the Facebook Integration tab, under IFrame size, I chose Auto-resize instead of Show scrollbars.
(2) I loaded the Facebook connect API (see code below).
(3) I called FB.Canvas.setAutoResize( 100 ) in two different places. I call it twice because it wasn't clear to me which location would make it take effect more quickly. In early testing, I was seeing the iframe height start out short (maybe 800 pixels tall) and then grow to the full size of my content (maybe 1100 pixels tall). In subsequent tests the iframe resizes immediately so I don't see the two states. So I'm not totally clear on the timing/mechanism here.
<body>
<div id="fb-root">
</div>
<script src="http://connect.facebook.net/en_US/all.js" type="text/javascript"></script>
<script type="text/javascript">
FB.init({
appId : 'your app id here',
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
xfbml : false // parse XFBML
});
FB.Canvas.setAutoResize( 100 );
</script>
... the rest of the page body goes here ...
<script type="text/javascript">
FB.Canvas.setAutoResize( 100 );
</script>
</body>