Skip to content
Advertisement

Using Fancybox’s Current image as document title

I currently have a web site I am building, with an image gallery on the posts. My question here is:

How do I take the current image’s title attribute, and make it the document title.

Explained:

When image one, with a title of “Beautiful, isn’t it?” is opened in the gallery, the document title is “Beautiful, isn’t it?”. Then, when image two, with the title of “Man! That car crash is horrible!” is in the gallery, the document title is “Man! That car crash is horrible!”. This is a gallery, so images can be advanced within the FancyBox, and on change to the new image, the document title changes to the new image. When FancyBox is closed, document title returns to before (which could be defined in a variable at the beginning of the document, if necessary).

Advertisement

Answer

document.title = 'This is easy!';

UPD:

have look at callbacks http://fancyapps.com/fancybox/#docs

$(document).ready(function() {
    var origTitle = document.title

    $("#single_1").fancybox({
          helpers: {
              title : {
                  type : 'float'
              }
          },
          afterShow: function() {
            document.title = $(this).attr('title');
          },
          afterClose: function () {
             document.title = origTitle;
          }
      });
});

full code on http://jsbin.com/olufus/1

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement