Search code examples
javascripturliframeautosize

pass parent url to iframe - iframe auto resize


I'm using a solution I found here on stackoverflow that auto sizes an iframe based on its content.

https://stackoverflow.com/a/362564/258594

My iframe is being used by several websites so I need the call to the helper file to be dynamic instead of hard coded. How can I pass the parent url to my iframe to change the following line.

pipe.src = 'http://www.foo.com/helper.html?height='+height+'&cacheb='+Math.random();

Solution

  • Ended up adding the url to the iframe src

    <iframe width="100%" height="100%" src="foo.html#http://www.ParentURL.com"></iframe>
    

    Then accessed it in the iframe srouce file

    URL = window.location.hash.substr(1);
    var height = document.body.scrollHeight;
    var pipe = document.getElementById('helpframe');
    pipe.src = URL + '/helper.html?height='+height+'&cacheb='+Math.random();