【发布时间】:2017-06-13 10:22:07
【问题描述】:
我有一个嵌入的iframe,它已创建发布一个谷歌文档。
iframe 自动为其body 应用一个大的填充,导致文本成为一个非常窄且丑陋的列。我必须改变它。
我已尝试创建自定义指令:
app.directive('iframeWithStyle', [function(){
return {
restrict: 'A',
link: function(scope, element, attrs){
element.on('load', function(){
var iframe = element[0];
var grabbedElement = iframe.querySelector("body");
// -> grabbedElement is null here
});
}
}}]);
适用于:
<iframe iframe-with-style
src="https://docs.google.com/document/d/somethingABC123/pub?embedded=true">
</iframe>
但是iframe.querySelector 会返回null 和iframe.contentWindow.document 结果,as expected,在
Uncaught DOMException: Blocked a frame with origin “http://localhost:8100”访问跨域框架。
我已经研究过一种解决方法,但我觉得它有点矫枉过正(例如:safe cross-communication with messages)。
我试图用一些 css 应用到我能到达的地方来对抗填充。 例如:
iframe {
padding: 0px !important;
margin-left: -50px;
margin-right: 50px;
}
应用于iframe 的body 的css 似乎被简单地忽略了。
曾几何时,有一些便利属性,例如marginwidth。也试过了。
我还想知道谷歌是否不提供一些“糖”,但谷歌搜索并没有帮助。
注意:它实际上不必是iframe,但我需要在应用程序中以可读的方式显示该格式化的 gdoc;为此,我需要减少填充。
【问题讨论】:
-
添加要应用
Directive的html元素代码 -
我已经添加了要应用该指令的 html 代码。
-
感谢@SaiUnique,但
iframe由谷歌提供。这就是问题所在。 -
我认为最好有一个父元素来设置
iframe的样式。只需设置父级的样式而不是iframe
标签: angularjs iframe google-docs