Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
256 views
in Technique[技术] by (71.8m points)

asp.net - Resizing jQuery dialog div on iFrame content height change, where iframe contained in dialog

I've a jquery dialog div. The div contains an iFrame to another ASP.Net page on the same domain. The iframe source page also contains jquery accordion control. Whenever the dialog is opened and accordion are expanded/collapsed, I need to resize the dialog box. Currently the contents are getting chopped off. Please note again that the dialog wraps the accordion within an iframe. I'm breaking my head against the wall to make things work. If somebody have a solution to this, then please help me out. Note: Everything is in same domain.

SOLVED See my ANSWER below.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You need to get the child iframe to talk to the parent window when the accordion is toggled.

$yourAccordion.on('open', function(e){
  if(window.top && window.top.resizeDialog)
     window.top.resizeDialog($(window).width(),$(window).height());
});

Then in your parent page, have a global function called resizeDialog

window.resizeDialog = function(w,h){
  $('#dialog').find('iframe').attr({
    width: w,
    height: h
  });
};

Note: You'll most likely need to account for animation timing etc. You could also include this in the step function of the jQuery animate method you use to open/close the accordion to make it a bit smoother.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...