When copying and pasting the following code for a Twitter button into a text file:
<a href="https://twitter.com/share" class="twitter-share-button" data-via="jpkcambridge">Tweet</a>
<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="//platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script>
I get a javascript error saying 'failed to load resource file://platform.twitter.com/widgets.js'
What could be causing this? Thought I should be able to just copy and paste the code from Twitter.
You're trying to load a protocol-less URL in a local file. Twitter is serving its script via //platform.twitter.com/widgets.js
, which translates to the file:
protocol locally. That's the best practice for serving content (it will not generate those annoying mixed content warnings in IE), but just plain won't work in local files.
Try updating that line of the script to https://platform.twitter.com/widgets.js
. That should help you test locally; once you're done testing, flip it back to the protocol-less structure.