Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>What you could try is to use an ajax call, and when it returns set the size of the iframe.</p> <pre><code>// get AJAX http request var xmlhttp = getXMLHttpRequest(); function getXMLHttpRequest() { var xhr; if (window.XMLHttpRequest) { //code for IE7+, Firefox, Chrome, Opera, Safari xhr = new XMLHttpRequest(); } else { //code for IE6, IE5 xhr = ActiveXObject("Microsoft.XMLHTTP"); } return xhr; } </code></pre> <p>Send AJAX request and listen for response:</p> <pre><code>window.doit = function() { xmlhttp.onreadystatechange = function () { if (xmlhttp.readyState == 4 &amp;&amp; xmlhttp.status == 200) { //This is used when AJAX returns //xmlhttp.responseText contains all markup sent back from google //Determine size of iframe $("#if2").attr('width', '100%'); $("#if2").attr('height', textHeight(xmlhttp.responseText) + "px"); //Used to set the contents of the iframe //May have to be adapted to get the response to a specific place in the iframe tag hierarchy $("#if2").attr('src', "data:text/html;charset=UTF-8," + escape(xmlhttp.responseText)); } }; xmlhttp.open("POST", "http://google.com/cse", true); xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); xmlhttp.send("cx=009827885688477640989:igzwimalyta&amp;ie=UTF-8&amp;q=31"); }; </code></pre> <p>Measure the height of the response (adapted from <a href="https://stackoverflow.com/questions/1582534/calculating-text-width-with-jquery">Calculating text width</a>):</p> <pre><code>//Measures the size of the returned text function textHeight(text){ $("body").append('&lt;span id="tempSpan" style="display:block;"&gt;' + text + '&lt;/span&gt;'); var height = $("#tempSpan").height(); $("#tempSpan").remove(); return height; }; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload