use*_*438 2 html javascript google-docs
如何在 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>
Run Code Online (Sandbox Code Playgroud)
显示屏可能会显示一页半的文本并停止。
Google 文档目前很乐意通过 CORS 请求提供已发布的文档。
这意味着您不需要iframe嵌入文档。您可以改为XMLHttpRequest在GET文档中使用 an 并将响应放入 adiv中innerHtml。
| 归档时间: |
|
| 查看次数: |
3986 次 |
| 最近记录: |