Both main window and iframe are on the same domain, but what I want to achieve is to resize iframe to fit its contents using js only within that iframe.
I also do no
For same-origin content like yours, yes you can.
To borrow from Gary's answer on the above question:
In the iframe, window.parent refers to the global object of the parent document, not the document object itself. I believe you would need to use parent.document.getElementById
Try accessing the iframe using parent.document, and see if this solves your issue.