可编辑的嵌入式Google文档

时间:2017-10-09 19:03:45

标签: javascript html iframe web doc

我正在创建一个网站来指导我校的人员,我需要嵌入一个谷歌文档,以便访问该页面的任何人都可以在使用他们的谷歌帐户登录后进行编辑。我现在的方式,它是不可编辑的,但它确实嵌入。有谁知道怎么做,甚至可以做到吗? 这是我到目前为止所拥有的。



<iframe src="GOOGLE-DOC-URL" height = "1000" width = "1000"></iframe>
&#13;
&#13;
&#13;

我公开发布了这个页面并发布了它,我已经做了相当多的研究并发现添加&#34;无缝&#34;到iframe语句用于工作,但现在显然已被弃用,我试过,它不起作用。谢谢。

1 个答案:

答案 0 :(得分:0)

首先,您需要使用此参数添加URL google doc:

  

https://docs.google.com/document/d/KEY/pub?embedded=true

其次我做一个ajax调用来获取来自google doc api的信息和响应:

https://codepen.io/headmax/pen/dVeMmE

要创建您自己的页面: HR html元素之后的 API文档打印

html页面:

<html>
<body>
<h1>The text below is pulled live from Google Docs</h1>
<h4>If there is an update to the doc and you refresh the page, it should update.</h4>
<hr>
<script>
function get_information(link, callback) {
    var xhr = new XMLHttpRequest();
    xhr.open("GET", link, true);
    xhr.onreadystatechange = function() {
        if (xhr.readyState === 4) {
            callback(xhr.responseText);
        }
    };
    xhr.send(null);
};

//Now initilisation and call & working from the anonyme callback function with dom response :

get_information("https://docs.google.com/document/d/1yf5plpYBYsBMCaeeDpTkapgR8jZtg4XCfiTvRG5qRWY/pub?embedded=true", function(text) {
    var div = document.createElement("div");
    div.innerHTML = text;

    // Remove css that comes with Google Doc embeds
    // If you want the Google Doc styling, comment these out
    div.removeChild(div.childNodes[1]);
    div.removeChild(div.childNodes[0]);

    document.body.appendChild(div);
    document.body.appendChild(document.createElement("hr"));
  }
 );
</script>
</body>
</html>