Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums CSS document.write in anythingSlider

  • This topic is empty.
Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #39504
    stinkyboomboom
    Participant

    Hi, I’m using the anythingSlider on a client website, and they want to implement google adsense on one of the text slides. It looks like any script that does a document.write within an anythingSlider slide will overwrite the entire window with whatever the value is when anythingSlider is initialized.

    I thought maybe it was because of the cloning of panels, so I set this, but it didn’t help.

    infiniteSlides: false

    Do you know of any way around this?

    Thanks!

    #108542
    stinkyboomboom
    Participant

    Adding a demo of the issue. Here’s the link. This is the default anythingSlider package, the only thing I did was add this to #slider1:

            

  • And this to the $(‘#slider1’).anythingSlider(); options:

            infiniteSlides: false,
    #108553
    Mottie
    Member

    Hi Stinkyboomboom!

    Yeah, using a document write won’t work inside of the slider. It wraps the contents in a div, and wraps the whole slider in a few more divs, this means that the document write is removed from the dom then re-applied making it replace the entire page because the page, and dom, have finished loading.

    There are always alternatives to this. One solution would be to put the document write in a hidden div outside of the slider, then transfer the contents into the slider before it initializes, like this (demo):

    $('#slider').anythingSlider({

    // Callback before the plugin initializes
    onBeforeInitialize: function(e, slider) {
    var dw = $('#docwrite'), newstuff;
    // remove document.write
    dw.find('script').remove();
    // get added content
    newstuff = dw.html();
    // add a new slide
    slider.$el.find('li:eq(0)').after( '
  • ' + newstuff + '
  • ' );
    }

    });​
    #108554
    stinkyboomboom
    Participant

    Awesome, thanks for the reply Mottie, and thanks for the alternate solution with demo code.

Viewing 4 posts - 1 through 4 (of 4 total)
  • The forum ‘CSS’ is closed to new topics and replies.