Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9209029
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T00:44:48+00:00 2026-06-18T00:44:48+00:00

I have a slideshow web application that for some slides include a beforeSlideshowAction that

  • 0

I have a slideshow web application that for some slides include a beforeSlideshowAction that is rendered from serverside together with that slide, the javascript is rendered together with the contents of that slide since it is part of a slide-template generating this content.

However, the javascript functions as of below is not updated together with my content. For example, if I were to load the slideshow, then switch places on these two slides (which update will be done by ajax after the slideshow has ran a full cycle), the beforeSlideshowAction_slide1() as of below will now be rendered as beforeSlideshowAction_slide2(), but when called, there will only exist a function called beforeSlideshowAction_slide1(), I assume all javascript function are registered upon page initial load only.

I remember solving a similar issue another time by calling eval on the script block containing the updated function, is there a less hackish solution to my problem?

{# comment: from here the document will be updated by Ajax #}
<div id="slideshowbody">

    {# comment: ordernumber is now 1 #}
    <div id="slide{{ ordernumber }}">

        //some content goes here

        <script>
        function beforeSlideshowAction_slide{{ ordernumber }}() {

            //assign appropriate value to videoContent for current slide
            videoContent[{{ ordernumber }}]='video={{ data0 }}&height={{ data1 }}&width={{ data2 }}&codec={{ data3 }}&fullscreen={{ data5 }}';

        }
        </script>

    </div>


    {# comment: ordernumber is now 2 #}
    <div id="slide{{ ordernumber }}">

        //some content goes here

        //slide 2 doesn't have a function for a "beforeSlideshowAction"

    </div>

</div>

Don’t worry that I might be calling a function that doesn’t exist, I do it in a try/catch block, I have set it up so that a beforeSlideshowFunction is called for each slide in a try/catch, and in the slide-template I just define a function there if I want one, if not I just skip it.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T00:44:49+00:00Added an answer on June 18, 2026 at 12:44 am

    Here is how I ended up solving it

    <script id="beforeSlideshowAction{{ ordernumber }}_script" type='text/javascript'>
    
    //define the function for later use (page updates)
    window.beforeSlideshowAction_slide{{ ordernumber }} = function() {  
    
        console.log('runnin beforeSlideshowAction for slide {{ ordernumber }}');
    
        //assign appropriate value to videoContent for current slide
        videoContent[{{ ordernumber }}]='video={{ data0 }}&height={{ data1 }}&width={{ data2 }}&codec={{ data3 }}&fullscreen={{ data5 }}';
    
    }
    
    //run
    var x = window['beforeSlideshowAction_slide{{ ordernumber }}'];
    x();
    
    </script>
    

    …and later on, when this has been changed by ajax and the slide1 function might instead be the slide3-function…

                //replace the innerHTML of body with the new stuff
                document.getElementById('slideshow_body').innerHTML=newContent;
    
    
                //update the videoContents and run other beforeSlideshow-actions
                for (var i=1;i<(pauseTimes.length+1);i++)
                { 
    
                    try {
                        console.log('slide '+i+' action...');
    
                        //set previous version of beforeSlideshowAction i to null
                        window['beforeSlideshowAction_slide'+i] = null;
    
                        //define it anew (will this run it too?)
                        ie_compatible_eval( document.getElementById('beforeSlideshowAction'+i+'_script').innerHTML )
    
                    }
                    catch(e) {
                        console.log('slide '+i+' none');
                        //do nothing since we will not have a function named that for every slide, error is expected
                    }
    
                }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a web app that contains a slide show with about 10 large
I have a requirement to put together an application which will generate a web
I have a slideshow that everytime you press a button show a new slide.
Right now, we have a slideshow of images that uses javascript. However, when the
i have a slideshow that is using the cycle plugin and for some reason
I have a JavaScript slideshow that pre-loads images out of a MySQL database and
I have a slideshow component that I wrote in javascript using jQuery. The slideshow
I have a slideshow that has 5 slides (each has an individual id) and
I have this slideshow that I'm trying to simply move up, but I can't
I have a slideshow built in flash that I want to mimic in jQuery.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.