amphtml icon indicating copy to clipboard operation
amphtml copied to clipboard

Add API to amp-ad to expose parent viewport size?

Open banderson623 opened this issue 10 years ago • 3 comments

I've possibly overlooked this, but is there a way to expose the width of the article that the amp-ad is located in? If not, could you add a method to window.context that could return the width of the parent article?

We are trying to run ads that maintain their aspect ratio and they want to be 100% width of their parent element. After #2263 is merged we'll have a working resize :tada:! And the last thing we'd need to get our custom ads fully supported would be this functionality.

banderson623 avatar Feb 24 '16 23:02 banderson623

You can just make the ad layout="responsive" which gets you the sizing you need (also check out the heights attribute). Then inside the iframe you can just measure its size and you should be good. We could pass it down, but you also have to handle the case of resizing (e.g. on device rotation).

cramforce avatar Feb 24 '16 23:02 cramforce

+1 to using layout="responsive"

camelburrito avatar Feb 25 '16 03:02 camelburrito

This fixed it! :tada: thanks @sriramkrish85 and @cramforce

banderson623 avatar Feb 25 '16 20:02 banderson623