amphtml icon indicating copy to clipboard operation
amphtml copied to clipboard

Resize Event not affecting inline width & height on amp-ad container

Open Re-lM opened this issue 10 years ago • 11 comments

Related to https://github.com/ampproject/amphtml/issues/2192 Since this is closed, open a new issue.

I'm calling window.context.requestResize(0,0) and the iframe itself is resized to 0/0. However, within the AMP-AD container there is an inline style width and height that does not seem to be adjusted.

This is the output after window.context.requestResize(0,0) has been executed: <amp-ad width="0" height="0" type="improvedigital" data-placement="869276" data-optin="y" class="-amp-element -amp-layout-fixed -amp-layout-size-defined -amp-layout" id="AMP_2" style="width: 300px; height: 250px;"></amp-ad>

style="width: 300px; height: 250px is still unchanged?

I resize the iframe when the ad has been served: <div id="c" style="position:absolute;top:0;left:0;bottom:0;right:0;"> <script>draw3p()</script><script src="https://ad.360yield.com/adj?p=869276&amp;w=300&amp;h=250&amp;optin=y&amp;tz=-60"></script> <script> window.context.requestResize(0,0); </script></div>

The main purpose it to collapse the amp-ad container. I tried using: window.context.noContentAvailable but this will just remove the ad but not change the AMP-AD container size. The size stays the same.

Please help.

@dvoytenko I made a new issue as the last one was closed.

Re-lM avatar Mar 18 '16 12:03 Re-lM

/to @sriramkrish85

I think 0/0 specifically have to be handled with context.noContentAvailable(). @sriramkrish85 could you please confirm/research?

dvoytenko avatar Mar 18 '16 16:03 dvoytenko

@Re-lM - With window.context.noContentAvailable or window.context.requestResize(0,0) there is a possibility that the resize might not happen (which is intentional to avoid visible content from getting moved due to change in scroll position).

You can confirm this by listening to window.context.onResizeDenied and see if it is getting called back

@dvoytenko ill remove setting height/width attributes before a successful resize., this was there won't be a confusion.

camelburrito avatar Mar 18 '16 21:03 camelburrito

@sriramkrish85 i think you misunderstood me. It seems like the method window.context.requestResize works as the actual width and height of the AMP-AD container has been resized to 0/0. Only there is an additional inline style on the AMP-AD container with a width (300) and height (250) that was not changed. Is this the expected behaviour?

Re-lM avatar Mar 18 '16 21:03 Re-lM

@Re-lM - i did understand you :) if the AMP-AD container has style attribute with width and height unchanged - then the change height request possibly failed. Could you try and listen to window.context.onResizeDenied(function(requestedHeight) { console.log('resize failed: for height = ' + requestedHeight ); });

and let me know if it gets called. Also if you have a URL that i can debug that will help me understand better.

camelburrito avatar Mar 18 '16 22:03 camelburrito

@sriramkrish85 aaah, Ok. I just added the change. As I am testing with a live campaign this change will take up to an hour to be actual live. Unfortunately, I have no staging environment where I can fake the whole process. Hence seeing the output will take another hour.

I tried to put it live but as I am working on a not yet certified ad network I had to change some things to stay in develop mode while live. Unfortunately, I think I missed here and there a connection hence the live version is now returning: not whitelisted..... Somewhere it is still referring to the production file, I think.

URL: http://improve.vo.llnwd.net/o45/ID_Default/amp/

Re-lM avatar Mar 18 '16 22:03 Re-lM

@sriramkrish85 I just double checked it and I don't see it called. Weird I don't see it being logged as well. There is however from the development the following in console: "[Resources]" "change height requests:" 1

Re-lM avatar Mar 23 '16 10:03 Re-lM

@sriramkrish85 any update on this one? Does added to current sprint mean that it is a bug and will be fixed in the current sprint? Many thanks!

Re-lM avatar Mar 29 '16 14:03 Re-lM

@Re-lM we did make updates to inner working of resize - could you check and see if that actually fixes this for you- else if you can put up an example that i can debug! Thanks a lot for the help!

camelburrito avatar Mar 29 '16 17:03 camelburrito

@sriramkrish85 thanks for the update. I will test it. Our AMP integration should come in the next release. Than I will be able to give you a live example. Thanks for the help!

Re-lM avatar Mar 30 '16 14:03 Re-lM

Rolling this into next milestone.

rudygalfi avatar Apr 01 '16 19:04 rudygalfi

Closing this for now as https://github.com/ampproject/amphtml/pull/2584 should have fixed this. Please re-open if you see any more issues.

camelburrito avatar Apr 05 '16 17:04 camelburrito