How to execute javascript iframe in custom module? I have created a custom module for Drupal 7. In this module, I would like it execute a javascript file that embeds an iframe when the module is viewed. I have tried the following code with no success:

function chat_with_librarian_block_view($delta = '') {

  $block = array();
  switch ($delta) {
    case 'chat_with_librarian':
      $block['subject'] = t('Ask a Librarian');
      $block['content'] = chat_with_librarian_get_html();
      break;
  }
  return $block;
}

function chat_with_librarian_get_html() {

  $html = '&lt;div id="qpchatwidget" &gt;' .
    '&lt;/div&gt;' .
    '&lt;script ...call site in question with appropriate parameters...&gt;' .
    '&lt;noscript&gt;Please enable javascript to chat with librarians online&lt;/noscript&gt;&lt;/script&gt;';
  $form = array(
    'chat_frame' =&gt; array(
      '#type' =&gt; 'markup',
      '#markup' =&gt; $html,
      '#prefix' =&gt; '&lt;div id="parent"&gt;',
      '#suffix' =&gt; '&lt;/div&gt;',
    )
  );
  return $form;
}


What do I need to do to get the embedded javascript to work properly. As a side note I can make this work by creating a block through the administration screen, so I know this can be done. I just need to know what I am missing in my code to accomplish the same thing. When I do execute this code, the title is rendered but the body isn't. Examining the body of the block, I can see it contains the javascipt as returned by the function and an additional message:

Reload the page to get source for: url


It seems like the executing code cannot get correct div dimensions to return a proper iframe (but that is just a guess on my part - have put inline css to define a size). Has anyone come across something like this or how to get this working?

Thanks.
The $form var in chat_with_librarian_get_html()is rather useless, just return the $html var instead and it should work.

function chat_with_librarian_get_html() {
  $html = '&lt;div id="parent"&gt;&lt;div id="qpchatwidget" &gt;&lt;/div&gt;' .
    '&lt;script ...call site in question with appropriate parameters...&gt;' .
    '&lt;noscript&gt;Please enable javascript to chat with librarians online&lt;/noscript&gt;&lt;/script&gt;&lt;/div&gt;';
  return $html;
}