Link to home
Start Free TrialLog in
Avatar of Colin Brazier
Colin BrazierFlag for United Kingdom of Great Britain and Northern Ireland

asked on

What does this javascript do?

Hi experts, I copied this link from the Twitter website into my code and would like to know what it does, my Twitter link still works without it.

<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?'http':'https';if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=p+'://platform.twitter.com/widgets.js';fjs.parentNode.insertBefore(js,fjs);}}(document, 'script', 'twitter-wjs');</script>

Open in new window

Thanks,
Col
SOLUTION
Avatar of Kimputer
Kimputer

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Colin Brazier

ASKER

OK thanks, but then shouldn't it make a difference if I leave the script out?  It doesn't seem to...
<figure>
                	<a href="https://twitter.com/fobgfc" data-show-count="false" data-size="large" target="_blank" ><img src="gifs/twitter.gif" alt="Follow us on Twitter" title="Follow us on Twitter" /></a>
                    <script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?'http':'https';if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=p+'://platform.twitter.com/widgets.js';fjs.parentNode.insertBefore(js,fjs);}}(document, 'script', 'twitter-wjs');</script>
                </figure>

Open in new window

Avatar of Kimputer
Kimputer

It only loads the correct code. If you didn't use the widget code somewhere else, it's useless.
You probably only wanted a link, making the widget totally unnecessary.
OK thanks, but then shouldn't it make a difference if I leave the script out?
If you leave it out and your page still works then you don't need it.
Thanks.
You are welcome.