iFrame CSS.
<body onload="onLoad()">
<script>
function onLoad() {
var twitter_iframe = document.getElementById('twitter-widget-0');
var twitter_document = twitter_iframe.contentDocument || twitter_iframe.contentWindow.document;
var twitter_timeline = twitter_document.getElementsByClassName("timeline-Widget")[0];
twitter_timeline.style = "left:0;right:0;margin:auto;padding:auto;min-width:100%;";
}
</script>
Note. Obviously, this may stop working if they set up their JS, but the good news is that it won’t break your page or something like that, it just goes back to not having a 100% width.
Edit:
I made a more reliable attack on this, since twitter sometimes loads after calling body onLoad. The following approach will also capture them in almost all cases:
function onLoad() {
resizeTwitterFeed();
setTimeout(function(){ resizeTwitterFeed(); }, 100);
setTimeout(function(){ resizeTwitterFeed(); }, 250);
setTimeout(function(){ resizeTwitterFeed(); }, 500);
setTimeout(function(){ resizeTwitterFeed(); }, 750);
setTimeout(function(){ resizeTwitterFeed(); }, 1000);
setTimeout(function(){ resizeTwitterFeed(); }, 2000);
setTimeout(function(){ resizeTwitterFeed(); }, 3000);
setTimeout(function(){ resizeTwitterFeed(); }, 5000);
setTimeout(function(){ resizeTwitterFeed(); }, 10000);
}
function resizeTwitterFeed() {
var twitter_iframe = document.getElementById('twitter-widget-0');
if (twitter_iframe) {
var twitter_document1 = twitter_iframe.contentDocument;
if (twitter_document1) {
var twitter_timeline1 = twitter_document1.getElementsByClassName("timeline-Widget")[0];
if (twitter_timeline1) {
twitter_timeline1.style = "left:0;right:0;margin:auto;padding:auto;min-width:100%;";
}
}
var twitter_document2 = twitter_iframe.contentWindow.document;
if (twitter_document2) {
var twitter_timeline2 = twitter_document2.getElementsByClassName("timeline-Widget")[0];
if (twitter_timeline2) {
twitter_timeline2.style = "left:0;right:0;margin:auto;padding:auto;min-width:100%;";
}
}
twitter_iframe.onload = function() {
resizeTwitterFeed();
return true;
}
}
}
source
share