如何在 iframe 上显示没有滚动条的嵌入式 google 文档的完整长度?
<html>
<style>
body { margin: 0; padding: 0; o}
iframe { margin-left: 2vw; margin-top: 2vh; height: 100%; width: 90vw; }
</style>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
<body>
<iframe srcdoc="" frameborder="0" scrolling="no" height="100%"></iframe>
<script>
$(function() {
$.get("https://docs.google.com/document/d/17OkIgtNdV1flno_783tJm2xWU0NBh7uEmZ5wEXP2E9g/pub?embedded=true", function(html) {
var contents = $("iframe").contents();
contents.find("html").html(html);
setTimeout(function() {
contents.find('a[href^="http://"]').attr("target", "_blank");
contents.find('a[href^="https://"]').attr("target", "_blank");
}, 1000); // Actually not sure if timeout is required here...
});
});
</script>
</body>
</html>
显示可能显示一页半的文本然后停止。
最佳答案
Google 文档目前很乐意通过 CORS 请求提供已发布的文档。
这意味着您不需要 iframe
来嵌入您的文档。您可以改为使用 XMLHttpRequest
来GET
您的文档并将响应放在 div
的 innerHtml
中。
关于javascript - 显示文档的全长以嵌入谷歌文档,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49566806/