javascript - 无法将推文嵌入 HTML

标签 javascript html twitter

我正在尝试通过 this method 将推文嵌入到我的网站中.

但我无法做到正确。这是我的 HTML 标记:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<blockquote class="twitter-tweet" lang="en">
  <p lang="en" dir="ltr">Can you answer this? Tem como calcular a diagonal no Canvas? <a href="http://t_.co/E8dD01jGKX">http://t_.co/E8dD01jGKX</a> <a href="https://twitter.com/hashtag/javascript?src=hash">#javascript</a></p>
  &mdash; SO em Português (@StackOverflowPT) <a href="https://twitter.com/StackOverflowPT/status/613791039539806208">June 24, 2015</a></blockquote>
<script async src="//platform.twitter.com/widgets.js" charset="utf-8"></script>
</body>
</html>

我在浏览器中看到的是:

enter image description here

只是 HTML,而不是 Twitter 嵌入推文框的样式。

最佳答案

到 Twitter 的 widgets.js 的链接是所谓的相对协议(protocol)或无方案:它没有定义自己的 URI scheme并使用其主机页面恰好打开的任何内容。这对于支持 httphttps 方案非常有用,而无需更改源代码中的链接。

现在,因为您正在使用本地文件进行测试,所以使用的方案是 file,即 specifically created对于与浏览器位于同一台计算机上的文件。因此无协议(protocol) //platform.twitter.com/widgets.js 获取 file 方案并成为本地文件 widgets.js 的链接code> 位于 platform.twitter.com 文件夹中,您的计算机上可能没有该文件夹。

要解决这个问题,只需添加一个方案,httphttps,如下所示:

<!DOCTYPE html>
<html>

<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <title>Untitled Document</title>
</head>

<body>
  <blockquote class="twitter-tweet" lang="en">
    <p lang="en" dir="ltr">Can you answer this? Tem como calcular a diagonal no Canvas? <a href="http://t.co/E8dD01jGKX">http://t.co/E8dD01jGKX</a>  <a href="https://twitter.com/hashtag/javascript?src=hash">#javascript</a>
    </p>
    &mdash; SO em Português (@StackOverflowPT) <a href="https://twitter.com/StackOverflowPT/status/613791039539806208">June 24, 2015</a>
  </blockquote>
  <script async src="https://platform.twitter.com/widgets.js" charset="utf-8"></script>
  <!--                 ^                -->
</body>

</html>

关于javascript - 无法将推文嵌入 HTML,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31036649/

相关文章:

javascript - (Redux 表单)您必须将 onSubmit 函数传递给 handleSubmit() 或将 onSubmit 作为 prop 传递

javascript - 删除列表中的特定对象时出现问题

javascript - 为什么这个数组访问不起作用?

javascript - 使用 Javascript 的 HTML 中的下拉问题

javascript - 推文按钮 Iframe

javascript - 如何将传递给 Nodejs 的查询字符串转发到通过 res.render 提供服务的页面?

javascript - 使用Python-Selenium过滤信息时点击不起作用

html - 为元素提供超过 100% 的宽度后,移动端 html 标签外页面底部的空白

python - 如何使用 cron 在 Raspberry Pi 上自动化 Python 程序?

ios - TwitterKit : Can't bypass Fabric consumer key and app id