bendqh1
December 15, 2021, 2:15pm
1
I need to add 25px to an iframe with somewhat dynamic height, to compensate for 25px of padding that this iframe already got (and by doing so ridding end-users from the need to scroll-down these extra 25px).
I tried this:
iframeToWorkOn.height += "25px";
It added about 47525px instead just 25px and I have no clue why.
You don’t need to set it by pixels - that should be the default dimension (I think)
iframeToWorkOn.height += 25;
bendqh1
December 15, 2021, 3:24pm
3
I still get about 47525px instead just 25, this way…
Gandalf
December 15, 2021, 3:28pm
4
I think it is probably concatenating the 25 onto the current frame height. You need to ensure it is performing an arithmetic addition.
What is the value of iframeToWorkOn.height
?
bendqh1
December 15, 2021, 3:34pm
5
bendqh1:
iframeToWorkOn.height
From executing iframeToWorkOn.height
in browser console its value is 300 (px).
Ahhh…should have looked closer and caught this - height returns a string.
So you’ll need to do something like this.
iframeToWorkOn.height = (parseInt(iframeToWorkOn.height) + 25);
1 Like
bendqh1
December 15, 2021, 3:58pm
7
Thanks, I think it works.
Just one question why is the parseInt()
method and the + 25 arithmetic operation where both wrapped in parenthesis?
You don’t need the wrapping parenthesis. I did it for readability but this works as well.
iframeToWorkOn.height = parseInt(iframeToWorkOn.height) + 25;
1 Like
system
Closed
March 16, 2022, 11:08pm
9
This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.