Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
James Ingmire
11,901 PointsTwitter widget <script> breaks layout on iphone. Anyway to remove js script on iphone, media query maybe? Please help..
When adding a twitter feed to the website the layout has a right margin on iphone, is there a way to remove the script completely as display:none etc does not work.
Is there a way to target through media queries. It is the code pulled from twitter.com > create a widget so surely someone else has this problem, cant find any other cases tho like it.
2 Answers
Andrew Kiernan
26,892 PointsHey James:
I'm not too familiar with the Twitter widget, but if it is just a script tag you add to your page, you can set your code up to check the screen size and add the script if the screen is big enough.
For example, in a different script you can do a check on page load:
window.onload = function () {
if (window.innerWidth > 1000) { // Set width as appropriate
var script = document.createElement('script');
script.src= '/path/to/twitter/widget/script';
document.body.appendChild(script); // Adds the script tag to the bottom of the page.
}
};
So if your window width is greater than 1000, the script gets added and your page will fetch the script for you, otherwise its not included.
That should be a quick and dirty way to do what you need.
Hope that helps!
-Andrew
Andrew Kiernan
26,892 PointsCorrect, you would add the twitter code to a separate file.
The path stuff just means to add the path to that file you put the code in. For example, if I had one on my site, and I put the widget code in a file called myWidget.js, and put that in a folder called scripts, the path to it would be scripts/myWidget.js. So you would use that as the path:
script.src = 'scripts/myWidget.js';
Let me know if you have any other questions.
-Andrew
James Ingmire
11,901 PointsWorked a treat, thank you, thank you, thank you kind sir... true legend. Saves me using a hacky negative margin etc lol.
James Ingmire
11,901 PointsJames Ingmire
11,901 PointsThat is fantastic thanks very much however bit of a beginner so what does this mean '/path/to/twitter/widget/script' would i put the path to a separate js file with the twiter code inside?
Thanks again