I have an embedded iframe
that has been created publishing a google doc.
The iframe
automatically applies a large padding to its body
resulting in the text being a very narrow and ugly column. I have to change that.
I have tried to create a custom directive:
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
});
}
}}]);
which is applied to:
<iframe iframe-with-style
src="https://docs.google.com/document/d/somethingABC123/pub?embedded=true">
</iframe>
but iframe.querySelector
returns null
and iframe.contentWindow.document
results, as expected, in
Uncaught DOMException: Blocked a frame with origin "http://localhost:8100" from accessing a cross-origin frame.
I have looked at a workaround but I have a feeling that it's overkill (ex: safe cross-communication with messages).
I tried to fight the padding with some css applied to what I can reach. For example:
iframe {
padding: 0px !important;
margin-left: -50px;
margin-right: 50px;
}
css applied to the body
of the iframe
seems to be simply ignored.
Once upon a time there were some convenience attributes, such as marginwidth
. Tried that too.
I was also wondering if google does not offer some "sugar" but googling around did not help.
Note: it really does not have to be an iframe
, but I need to show that formatted gdoc within the app in a way that it is readable; and for that I need to reduce that padding.
Adding a plunker: https://plnkr.co/edit/XIkgPe7ecLyFfhq1Q3Sv?p=preview