amphtml icon indicating copy to clipboard operation
amphtml copied to clipboard

amp-ad : get dom or container properties?

Open coreybyrnes opened this issue 9 years ago • 11 comments

From within a DFP amp-ad, is there a way to get top document DOM properties? For example I'm trying to get the browser width via window.top.innerWidth but am hitting cross-origin errors. I don't see any methods within context to obtain any page-level element properties other than these.

Alternatively, is there a way to use units other than 'px' within a call to context.requestResize? I'd like to set the width of the container to be the full width of the browser either with 100vw or 100% (or by getting the width of the page in pixels and using that value which is why I'm asking about getting top document DOM properties).

coreybyrnes avatar Mar 03 '17 15:03 coreybyrnes

/to @lannka

aghassemi avatar Mar 03 '17 17:03 aghassemi

/cc @bradfrizzell

keithwrightbos avatar Mar 08 '17 23:03 keithwrightbos

Would the window.context.observerIntersection return value not supply this? I believe that is what rootBounds gives you, no? I am currently on a train and my wifi is crap so I am unable to get my testing environment to work, but I can double check when I am back in the office.

bradfrizzell avatar Mar 09 '17 16:03 bradfrizzell

@bradfrizzell Can you point me to any documentation regarding rootBounds and observerIntersection? I've been digging around quite a bit and I haven't come across it. Thanks!

coreybyrnes avatar Mar 09 '17 18:03 coreybyrnes

@coreybyrnes @bradfrizzell I don't suggest relying on observerIntersection API for the window size. A better one will be the proposed PositionObserver API: #6873 .

But still, that would be considered expensive if all you want is parent window size. We can introduce a specific API for that.

Or alternatively, let me explore the option for 100% and 100vw first.

lannka avatar Mar 09 '17 19:03 lannka

Does requestResize take anything other than a pixel value? It does not appear so to me. Either way, the argument's units is not well documented anywhere in the code.

bradfrizzell avatar Mar 09 '17 19:03 bradfrizzell

@bradfrizzell Unfortunately not - you simply set a numeric value, not a string including a unit. That was part two of my question. If you can specify a unit as the third paramater or ideally make the unit a part of the parameter (with px being a fallback if no unit is included).

coreybyrnes avatar Mar 09 '17 20:03 coreybyrnes

@bradfrizzell @coreybyrnes yep, that's a feature missing. I'll take a look how easy it is.

lannka avatar Mar 09 '17 21:03 lannka

@lannka Awesome! Thanks.

coreybyrnes avatar Mar 09 '17 21:03 coreybyrnes

@lannka does this still need to be prioritized? Thanks.

adelinamart avatar Jun 29 '17 18:06 adelinamart

the discussion was continued (and stalled) in #8095 . we can close this

lannka avatar Jun 30 '17 21:06 lannka