Jump to content
  • 0
Didier

Iframe dynamic size

Question

Hi family,

 

 

i am currently using the following code to set the height and width of the iframe deployment manually:

 

<iframe name="Broker" title="Broker" src="https://c0dcv045.caspio.com/dp/aa4a60008d8bcb4785114729ba75" 
width=500 height=300>Sorry, but your browser does not support frames.</iframe>
 

This is as given on caspio's site so i just adjust it to my datapage...

 

However is very time consuming to have to pick and adjust the sizes everytime you deploy and given that the results will always grow as the system is used, the sizes must now be readjusted manually all the time.

 

how do i set it to always fit the screen automatically, so that the sizes grow with the growing results....

 

much appreciated in advance

 

 

Share this post


Link to post
Share on other sites

2 answers to this question

Recommended Posts

  • 0

Hello @Didier,

 

I was able to formulate a working solution by putting together workflows from external resources.

 

On the Footer of the DataPage you want to deploy as iframe, paste the snippet below (Make sure HTML Editor is disabled from the Advanced Tab).

 

//Script tested on Tabular Report
<script>

document.addEventListener('DataPageReady', function() {
  parent.postMessage(document.documentElement.scrollHeight, "*");
  console.log(document.documentElement.scrollHeight);
})

</script>

 

On cases of  Submission Form / Details Drilldown, you may want to put the snippet below on an HTML Block instead.

//Not tested
<script>
  parent.postMessage(document.documentElement.scrollHeight, "*");
  console.log(document.documentElement.scrollHeight);
</script>

 

Then, on the page where you will be embedding the iframe, place this code snippet:

Replace iframe src with the URL Deployment of your DataPage

<iframe id="ifr-cdr" src="https://xxx.caspio.com/dp/2abe231b344545ff9945230aaaeeffccc" frameborder="0">Sorry, but your browser does not support frames.</iframe>

<script>
// Create IE + others compatible event handler (Credits to: https://davidwalsh.name/window-iframe)
var eventMethod = window.addEventListener ? "addEventListener" : "attachEvent";
var eventer = window[eventMethod];
var messageEvent = eventMethod == "attachEvent" ? "onmessage" : "message";

// Listen to message from child window
eventer(messageEvent,function(e) {
  document.getElementById('ifr-cdr').height = e.data;
},false);
</script>

 

Works for me.

Hope this helps.

 

-DN31337!

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...