最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Twitter button failed to load resource file:platform.twitter.comwidgets.js - Stack Overflow

programmeradmin1浏览0评论

When copying and pasting the following code for a Twitter button into a text file:

<a href="" 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/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/widgets.js'

What could be causing this? Thought I should be able to just copy and paste the code from Twitter.

When copying and pasting the following code for a Twitter button into a text file:

<a href="https://twitter./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./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./widgets.js'

What could be causing this? Thought I should be able to just copy and paste the code from Twitter.

Share Improve this question asked Jul 6, 2012 at 16:07 JohnJohn 13.8k14 gold badges54 silver badges73 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 3

You're trying to load a protocol-less URL in a local file. Twitter is serving its script via //platform.twitter./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./widgets.js. That should help you test locally; once you're done testing, flip it back to the protocol-less structure.

Are you sure you've entered the code correctly? Try using a direct link target for your button like this: just change the URL to wherever you want to point it, and the username to whatever username you use. This code is the code from the site:

<a href="https://twitter./share" class="twitter-share-button" data-url="http://anawesomesite.html" data-text="super site of awesome" data-via="Username" data-related="face" data-hashtags="emplosion">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./widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script>

Should the src be "https://......" rather than just "//....." ?

发布评论

评论列表(0)

  1. 暂无评论