4

HTML is pretty simple, on my page I have

<div id="notificationDialog" title="View Notification"></div>

I dynamically load notifications based on the user viewing the page, and display them inside an iframe, which is inside a jQuery ui dialog. Basically,

function viewNotif(nid) {
  var wWidth       = jQuery(window).width();
  var dWidth       = wWidth * 0.5;
  var $notifIframe = jQuery('<iframe />', {
      name: 'myFrame',
      id:   'myFrame',
      src: "/modals/modal_notification.php?nid="+nid,
      width:"100%",
      height:"100%",
      align:"center",
      scrolling:"auto",
      frameborder:"0"
  }); 

  jQuery('#notificationDialog').html($notifIframe.clone());

  jQuery('#notificationDialog').dialog({
      autoOpen: false,
      height: auto,
      width: dWidth,
      modal: true
  });

  jQuery('#notificationDialog').dialog('open');
}

I am trying to access the height value of a div that is within the iframe inside the jQuery ui dialog, and have thus far been unable to do so. How would I get the height value of a div, id of the div is notification_container which is inside the iframe, inside notificationDialog?

EDIT - I should mention that the function is called in an onClick one the page, and passes the notification ID (nid) to display, to the function.

1 Answer 1

3
$("iframe").contents().find("#selector");

It should be noted that this is only allowable if the iframe contents are accessed locally. Otherwise you'll get an access denied error.

Sign up to request clarification or add additional context in comments.

3 Comments

This gives me this error Uncaught TypeError: Object #<HTMLIFrameElement> has no method 'contents'
The iframe is on the same server as the page, but in a different folder. Is that not 'local'?
I know this is an old question, but in case anyone stumbles upon it, the line above should be as follows: $("iframe").contents().find("#selector"); (i.e. without the [0])

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.