0

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();
Community
  • 1
  • 1
Adam
  • 2,632
  • 8
  • 34
  • 60

2 Answers2

1

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();
Adam
  • 2,632
  • 8
  • 34
  • 60
0

First Solution

<iframe width="100%" height="100%" src="foo.html"></iframe>

Second Solution

<iframe width="auto" height="auto" src="foo.html"></iframe>

foo.html

<body>
<div style="width:200px;height:300px;">
<p>Your all content</p>
</div>
</body>
Rizwan Mumtaz
  • 3,875
  • 2
  • 30
  • 31