我正在尝试从一个嵌入在iframe内部的Google链接到iframe之外打开。我尝试过几种解决方案。我尝试将基本目标定义为任意一个_parent、_top或_blank。Google在iframe中创建代码,所以我尝试用jquery更改它以更改目标属性,但这似乎行不通。
相关的html代码是:
<iframe id="googledoc" base target="_blank" scrolling=no width=1000 height=1000 src="https://docs.google.com/document/d/1ctn5fekV4odEepCREAfLg31PrNMGnmwqokY0wHXqu7s/pub?embedded=true">There was a problem fetching the frame.</iframe> <!-- scrolling=no is for backwards-compatibility, also implemented in css -->
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script>window.jQuery || document.write('<script src="js/vendor/jquery-1.10.2.min.js"><\/script>')</script>
<script src="../js/plugins.js"></script>
<script src="../js/iframefix.js"></script>注意基本目标是如何定义的,但似乎没有任何效果。
相关的jquery在iframefix.js中,如下所示:
$(document).ready(function () {
$('#googledoc').contents().find('a').each(function () {
$(this).attr('target', '_blank');
});
});我找到了一种与php一起工作的解决方案,但不愿使用php。有使用javascript/jquery的解决方案吗?
发布于 2014-04-26 10:10:21
确保iframe位于相同的域中,否则无法访问其内部。那将是跨站点脚本。
似乎您正在尝试在iframe中加载google文档,因此它来自其他域,并且没有浏览器允许您访问其中的元素。
几年前,我想要同样的东西,花了很多时间在背后。我意识到这是不可能的。
您可能需要使用pdf.js来显示文档。
https://stackoverflow.com/questions/23309274
复制相似问题