views:

25

answers:

3

Hello!

I have a background image in my site, but when I open a fancybox, that background image would appear in fancybox's body, too. Is there a way to get the body element inside the iframe so that I can apply an id to it?

I tried this:

$("#appointment-form").fancybox({
        'width'     : 500,
        'height'    : 300,
        'transitionIn'  : 'fade',
        'transitionOut' : 'fade',
        'type'      : 'iframe',
        'onComplete'    : function () {
                             $('body').attr('id', 'fancybox_body'); 
                          }
});

But it changes the id of the main page.

Thanks!

A: 

It changes the id because of

$('body').attr('id', 'fancybox_body');
Jean
What are you talking about? I don't understand.
Pekka
His question is the id changes on the main page, the reason is because of the above code.
Jean
A: 

Why do you need to change the body's ID in the first place?

Better give the main body a class like, say, page. Apply the background image only to bodies of that class.

body.page
 {
  background-image: url(.....)
}
Pekka
That is what I was trying to do. The hard part was adding an id (or class). I am working on a typo3 site and I managed this with typoscript. Thanks!
cili
A: 

You need to get at the <body> inside the <iframe> a slightly different way, like this:

$('#fancybox-frame').contents().find('body').attr('id', 'fancybox_body');

You need to first get the <iframe> fancybox uses with an #ID selector then do a .find() on it's .contents() to get elements inside.

Nick Craver
Thanks, Nick! I tried and it works, but I already found a more "native" solution in typo3. Thanks again!
cili
@cili - Welcome :) make sure to either accept an answer or post what you did as the answer (you can accept *that* 2 days after), it'll help the next person coming along with the same issue that googles and finds your question :)
Nick Craver