使用iFrame嵌入私有Google文档

Embed a Private Google Doc Using an iFrame

本文关键字:Google 文档 iFrame 使用      更新时间:2023-09-26

各位堆叠者,我的意图是使用iframe将私人谷歌文档嵌入到网页中,这样它的内容只加载给在谷歌文档上明确共享的用户。

为此,我想使用以下链接(https://docs.google.com/feeds/download/documents/Export?exportFormat=html&format=html&id=[MyGoogleDocID])将Google文档导出为.html。然后,如果上帝愿意,使用JavaScript将导出的.html文件呈现在iframe中。

我是JavaScript的新手,但我一直在使用以下代码(John亲切地推荐)来强制iframe中的嵌入超链接在新窗口中打开。。。因此,加载下载的.html文件的任务似乎在JavaScript的能力范围内:

<iframe id="myframe" srcdoc="" style="width: 600px; height: 500px; border: 0" frameborder="0"></iframe>
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script>
    $(function() {
        $.get("https://docs.google.com/document/d/[MyGoogleSpreadsheetID]/pub?embedded=true", function(html) {
            $("#myframe").attr("srcdoc", html);
            setTimeout(function() {
                $("#myframe").contents().find('a[href^="http://"]').attr("target", "_blank");
                $("#myframe").contents().find('a[href^="https://"]').attr("target", "_blank");
            }, 1000);
        });
    });
</script>

一如既往,任何见解都将不胜感激!

  • 编辑:谷歌有一个嵌入表单的选项(但不是其他各种文档):

    1. 转到"文件">"嵌入表单"
    2. 复制&粘贴嵌入代码(它已经是一个iframe)
    3. 粘贴到HTML文档中