有没有办法将github代码嵌入iframe?
这个问题可能令人困惑,所以让我澄清一下 Github允许您在repo中查看文件的源代码。我想把它们包括在iFrame中,但我不确定是如何做到的,并且怀疑以前有人已经这样做了有没有办法将github代码嵌入iframe?,iframe,github,Iframe,Github,这个问题可能令人困惑,所以让我澄清一下 Github允许您在repo中查看文件的源代码。我想把它们包括在iFrame中,但我不确定是如何做到的,并且怀疑以前有人已经这样做了 在我的例子中,我想添加到iframe中,这样人们就可以从我的网站上看到代码的发展过程。GitHub页面本身不会直接放在iframe中( 那就剩下你了 比如: 您应该能够我刚刚找到了一种使用 用法 获取github文件url并在其前面加上前缀,然后将结果嵌入到标记中: <script src="http://gist-i
在我的例子中,我想添加到iframe中,这样人们就可以从我的网站上看到代码的发展过程。GitHub页面本身不会直接放在iframe中( 那就剩下你了 比如:
您应该能够我刚刚找到了一种使用 用法 获取github文件url并在其前面加上前缀,然后将结果嵌入到标记中:
<script src="http://gist-it.appspot.com/http://github.com/$file"></script>
这是我刚做的一个测试。有效!:)
您需要对iframe和css进行一些修改,以使其在文档中不带标签的情况下工作,但也可以:
下面是一个具体的示例,说明如何通过GitHub API实现这一点。我们请求编码内容并将其直接插入iframe
<iframe id="github-iframe" src=""></iframe>
<script>
fetch('https://api.github.com/repos/ileathan/hubot-mubot/contents/src/mubot.coffee')
.then(function(response) {
return response.json();
}).then(function(data) {
var iframe = document.getElementById('github-iframe');
iframe.src = 'data:text/html;base64,' + encodeURIComponent(data['content']);
});
</script>
取('https://api.github.com/repos/ileathan/hubot-mubot/contents/src/mubot.coffee')
.然后(功能(响应){
返回response.json();
}).then(功能(数据){
var iframe=document.getElementById('github-iframe');
iframe.src='data:text/html;base64'+encodeURIComponent(data['content']);
});
这是正在运行的代码凌晨4:30我需要睡觉,所以我现在无法检查,但是返回的内容是用我的api密钥加密的还是仅用base64编码的??顺便说一下,非常感谢你。
<iframe frameborder=0 style="min-width: 200px; width: 60%; height: 460px;" scrolling="no" seamless="seamless" srcdoc='<html><body><style type="text/css">.gist .gist-data { height: 400px; }</style><script src="https://gist.github.com/sundbry/55bb902b66a39c0ff83629d9a8015ca4.js"></script></body></html>'></iframe>
<iframe id="github-iframe" src=""></iframe>
<script>
fetch('https://api.github.com/repos/ileathan/hubot-mubot/contents/src/mubot.coffee')
.then(function(response) {
return response.json();
}).then(function(data) {
var iframe = document.getElementById('github-iframe');
iframe.src = 'data:text/html;base64,' + encodeURIComponent(data['content']);
});
</script>