How To: Jump to a Specific Slide in a Separate Course

I get a lot of questions on how to link to a specific slide in another external course.  Today I’ll show you how that can be accomplished.

image


Scenario:

Suppose we have a bunch individually published Captivate tutorials on how to use Microsoft Office.  Each tutorial has three slides of intro content with the fourth slide as a how-to video.  We also have a completely separate Help system and we’d like to link from the help system, directly to the training video on slide four.

 

Step 1

The first step is setting up the button that will make the jump.  The URL behind the button needs to send the slide number to the Captivate course.  To do that, we send a URL parameter. It should look something like this:

The “?” in the URL is telling the browser that whatever comes after this question mark is a parameter.  A parameter is like a variable that holds a piece of information.  In our case, the parameter’s name is “slide” and it equals 4. 

 

Step 2

The second step is for our Captivate Course to capture this parameter, and jump to the requested slide.  We can do this by executing some JavaScript on Slide Entry of the first slide.

GetSlideParam();

function GetSlideParam(){
    if(window.location.href.indexOf('?slide=') != -1) { 
        var startIndex = window.location.href.indexOf('?slide=' ) + 7;
        var URL = window.location.href.toString();
        var slideNumber = URL.substring(startIndex);
      
        if(slideNumber != '' || slideNumber != null){
            setTimeout(function(){NavigateToSlide(slideNumber);}, 200);
        }
    }
}

function NavigateToSlide(requestedSlide){
    var cpObj = document.Captivate;
    cpObj.cpEISetValue('cpCmndGotoSlide',requestedSlide - 1); 
    cpObj.cpEISetValue('rdcmndResume',1);
}

Code Explanation

The first line executes the GetSlideParam() function.  This function checks the incoming URL to see if it contains our “?slide=” parameter.  If it does, it then captures the slideNumber using the JavaScript substring method.  On line 9, we check to make sure we have something in our slideNumber variable before moving forward.  If so, we execute our NavigateToSlide method using a setTimeout.  The setTimeout() method executes a function after the specified amount of time has elapsed.  THIS IS THE KEY TO MAKING THIS WHOLE THING WORK!!!  If you don’t use setTimeout(), you will end up with a grey Captivate screen.  Why?  A lot is happening in the first slide.  Captivate is dynamically creating all of the other slides.  When our JavaScript is executed at the entry of the first slide, slide 4 DOES NOT EXIST yet.  So we wait a set amount of time before navigating.  In our case, we waited 200 milliseconds (1 second = 1000 milliseconds).  If you’re jumping to slide 85, you may want to wait a little longer so that slide 85 is created before you jump to it.  You may have to edit the milliseconds to get the desired results.

 

Live Demo

(Note the “?slide=4“ in the URL)

http://captivatedev.com/demo/Cp5/JumpToSpecificSlide/JumpToSpecificSlide.htm?slide=4

 

Download Demo

http://captivatedev.com/demo/Cp5/JumpToSpecificSlide/JumpToSpecificSlide.zip

 

del.icio.us Tags: ,
  • pcapademic

    This is awesome. I’ve been banging my head against the problem for a little while.
    Quick question – is there a better way to parse the slide= option? If you use a two digit number, the script doesn’t work. I’ll try to see if I can get this idea to work (http://www.netlobo.com/url_query_string_javascript.html), but I don’t really know how a lot of this works.

    • pcapademic

      My mistake – I had the timeout set to a small value. The parsing seems to work fine.

    • Anonymous

      @pcapademic: It should work with a two digit number. If you leave off the 2nd argument in the substring method, as the example does, it will parse from the startIndex to the end of the string. Just make sure ?slide=12 is the LAST parameter in your URL link.

  • Ouija

    Is there a way to modify this code so that you could bring in specific parameters, such as “username” (instead of a slide number) and then assign that to a Captivate Variable?  I’m really trying to find a way to set variables on load of a presentation, and this looks like a possible option..

    • Anonymous

      @Ouija:  Yes!  Once you parse out the username from the query string, you can use the cpEISetValue() JS function to set the Cp variable.

  • bigbacon

    Are there any other functions like cpAllSlidesLoaded?

  • Walker Talker

    Hi,
    Does this works when tested locally?

    • http://twitter.com/CaptivatePro CaptivateDev.com

      I’d test on your local web server. I have not tried locally.

  • Grantis

    When i publish this project with adobe captivate 6 it doesn’t work, ignores the ?slide=4 completely

  • Grantis

    If I publish the project and run the htm file from my machine it doesn’t work, but when I load it up to my server and run it from there it works… Why??? how do I run this thing from my machine..?

    • http://twitter.com/CaptivatePro CaptivateDev.com

      When testing via Captivate (F12 web preview), you’re running the browser content and your JS locally… which from a security standpoint, is problematic. I test all my content from my personal web server on my machine. Since your content is going to end up on a web server anyway, this is a truer and more valid test. I’m hoping Adobe will include a web server with Cp 7 so we can test not just swf/htm output, but also our HTML5 output as well. We shall see…

      • Grantis

        Ok… is it possible run an swf file from a third party program by embedding the html?

        • http://twitter.com/CaptivatePro CaptivateDev.com

          When you say “embedding”, you mean what exactly? Any content running in a browser where the web address starts with http or https should be able to run just fine. If the web address starts with something like file:///C:/ or C://my folder/… that means the content is running locally and you will run into browser and flash security restrictions.

          • Grantis

            I published a .swf file that I wish to open at a specific slide, but I want to open the swf file from within a swf player, is there a way to send a command to the player, or open the file with a command line that can start the swf file at a specific slide? I can do it by putting javascript in my project but then I need to open the file in a browser which I’d like to avoid.

          • http://twitter.com/CaptivatePro CaptivateDev.com

            Is your main project web based or published as a .app or .exe? If your main project is web based, you won’t be able to open the other swf file without going through the browser.

          • Grantis

            I’d prefer the project to be a swf, is it possible to open the file on a specific slide if it’s published as an exe?

          • http://twitter.com/CaptivatePro CaptivateDev.com

            Unfortunately not. The JavaScript API only applies to web based content. If you need to run the project locally, I’d recommend using Adobe AIR. Inside of AIR, you can run JavaScript.

          • Grantis

            Thank you…

            Is it possible to go to a specific object in the project? for example I have a text caption in the project called Caption1, can I assign an action to a button that can go directly to that object?

          • http://twitter.com/CaptivatePro CaptivateDev.com

            No, but you can assign an action to go to a specific slide in a project.

          • Grantis

            OK, that I’ve done, but I often want to start a slide half way so going to an object in the project is alot easier than trying to work out which frame to go to.

            Is it a possibility to add a feature like that into the program?

          • http://twitter.com/CaptivatePro CaptivateDev.com

            Sorry, I misunderstood. If your caption is at a specific time on the timeline, then you CAN jump to that point on the timeline. You just have to know what frame to jump to (see cpCmndGotoFrameAndResume and cpInfoCurrentFrame)… and yes, it would be nice to be able to jump to an object on the timeline by name. Is it possible to add this feature? Sounds like a great idea for a widget… or submit a feature request to Adobe. https://www.adobe.com/cfusion/mmform/index.cfm?name=wishform&product=5

          • Grantis

            That I can do, thank you for your help, really helped clarify some things.